Skip to content

Commit

Permalink
Backend,Frontend,Tests: rm txDetail from SignedTx
Browse files Browse the repository at this point in the history
This commit removes the redundant proposal and metadata
from the SignedTransaction type.
  • Loading branch information
aarani committed Oct 5, 2023
1 parent 021e284 commit b7a8d1e
Show file tree
Hide file tree
Showing 13 changed files with 327 additions and 374 deletions.
154 changes: 69 additions & 85 deletions src/GWallet.Backend.Tests/Deserialization.fs
Original file line number Diff line number Diff line change
Expand Up @@ -95,83 +95,65 @@ type Deserialization() =
[<Test>]
member __.``signed btc transaction import``() =

let deserializedSignedTrans: SignedTransaction<IBlockchainFeeInfo> =
let deserializedSignedTrans: SignedTransaction =
Account.ImportSignedTransactionFromJson
MarshallingData.SignedBtcTransactionExampleInJson

// We can't validate proposal & metadata because it needs
// a valid on-chain transaction.

Assert.That(deserializedSignedTrans, Is.Not.Null)

Assert.That(deserializedSignedTrans.Currency, Is.EqualTo Currency.BTC)

Assert.That(deserializedSignedTrans.FeeCurrency, Is.EqualTo Currency.BTC)

Assert.That(deserializedSignedTrans.RawTransaction,
Is.EqualTo "0200000000010111b6e0460bb810b05744f8d38262f95fbab02b168b070598a6f31fad438fced4000000001716001427c106013c0042da165c082b3870c31fb3ab4683feffffff0200ca9a3b0000000017a914d8b6fcc85a383261df05423ddf068a8987bf0287873067a3fa0100000017a914d5df0b9ca6c0e1ba60a9ff29359d2600d9c6659d870247304402203b85cb05b43cc68df72e2e54c6cb508aa324a5de0c53f1bbfe997cbd7509774d022041e1b1823bdaddcd6581d7cde6e6a4c4dbef483e42e59e04dbacbaf537c3e3e8012103fbbdb3b3fc3abbbd983b20a557445fb041d6f21cc5977d2121971cb1ce5298978c000000")

Assert.That(deserializedSignedTrans.TransactionInfo, Is.Not.Null)
Assert.That(deserializedSignedTrans.TransactionInfo.Proposal, Is.Not.Null)
Assert.That(deserializedSignedTrans.TransactionInfo.Cache, Is.Not.Null)
Assert.That(deserializedSignedTrans.TransactionInfo.Metadata, Is.Not.Null)

Assert.That(deserializedSignedTrans.TransactionInfo.Proposal.Amount.ValueToSend,
Is.EqualTo(10.01m))
Assert.That(deserializedSignedTrans.TransactionInfo.Proposal.Amount.BalanceAtTheMomentOfSending,
Is.EqualTo 12.02m)
Assert.That(deserializedSignedTrans.TransactionInfo.Proposal.Amount.Currency,
Is.EqualTo(Currency.BTC))
Assert.That(deserializedSignedTrans.TransactionInfo.Proposal.DestinationAddress,
Is.EqualTo("13jxHQDxGto46QhjFiMb78dZdys9ZD8vW5"))
Assert.That(deserializedSignedTrans.TransactionInfo.Proposal.OriginAddress,
Is.EqualTo("16pKBjGGZkUXo1afyBNf5ttFvV9hauS1kR"))

let btcTxMetadata = deserializedSignedTrans.TransactionInfo.Metadata :?> UtxoCoin.TransactionMetadata
Assert.That(btcTxMetadata.Fee.EstimatedFeeInSatoshis, Is.EqualTo 10)
Assert.That(btcTxMetadata.Inputs.Length, Is.EqualTo 1)
Assert.That(deserializedSignedTrans.TransactionInfo.Metadata.FeeEstimationTime,
Is.EqualTo MarshallingData.SomeDate)

Assert.That(deserializedSignedTrans.TransactionInfo.Cache.Balances.Count,
Is.EqualTo 5)
Assert.That(deserializedSignedTrans.TransactionInfo.Cache.UsdPrice.Count,
Is.EqualTo 5)

[<Test>]
member __.``signed ether transaction import``() =

let deserializedSignedTrans: SignedTransaction<IBlockchainFeeInfo> =
let deserializedSignedTrans: SignedTransaction =
Account.ImportSignedTransactionFromJson
MarshallingData.SignedEtherTransactionExampleInJson

// Validate deserialized SignedTransaction
Assert.That(deserializedSignedTrans, Is.Not.Null)

Assert.That(deserializedSignedTrans.RawTransaction,
Is.EqualTo("doijfsoifjdosisdjfomirmjosmi"))

Assert.That(deserializedSignedTrans.TransactionInfo, Is.Not.Null)
Assert.That(deserializedSignedTrans.TransactionInfo.Proposal, Is.Not.Null)
Assert.That(deserializedSignedTrans.TransactionInfo.Cache, Is.Not.Null)
Assert.That(deserializedSignedTrans.TransactionInfo.Metadata, Is.Not.Null)
Is.EqualTo("f86b0185019d334a3482520894d2fdfa29d5ccbb8168ba248d59ded7a25396f84e87022a8ad81f98768026a06bb7c1f8f2b40ed2bc3a3b572cdde7fddb42a8d43c561c60580183b0ed8c2d9fa035183359feab8789642135a253371f80781f4a870f0cae8a7368c5d7e102a688"))

Assert.That(deserializedSignedTrans.TransactionInfo.Proposal.Amount.ValueToSend,
Is.EqualTo(10.01m))
Assert.That(deserializedSignedTrans.TransactionInfo.Proposal.Amount.BalanceAtTheMomentOfSending,
Is.EqualTo 12.02m)
Assert.That(deserializedSignedTrans.TransactionInfo.Proposal.Amount.Currency,
Is.EqualTo(Currency.ETC))
Assert.That(deserializedSignedTrans.TransactionInfo.Proposal.DestinationAddress,
Is.EqualTo("0xf3j4m0rjxdddud9403j"))
Assert.That(deserializedSignedTrans.TransactionInfo.Proposal.OriginAddress,
Is.EqualTo("0xf3j4m0rjx94sushh03j"))
Assert.That(deserializedSignedTrans.Currency,
Is.EqualTo(Currency.ETH))

Assert.That(deserializedSignedTrans.FeeCurrency,
Is.EqualTo(Currency.ETH))

let etherTxMetadata = deserializedSignedTrans.TransactionInfo.Metadata :?> Ether.TransactionMetadata
Assert.That(etherTxMetadata.TransactionCount, Is.EqualTo(69))

// Validate generated proposal
let proposal = Account.GetTransactionProposal deserializedSignedTrans

Assert.That(proposal.Amount.ValueToSend,
Is.EqualTo(0.000609725773224054m))
Assert.That(proposal.Amount.Currency,
Is.EqualTo(Currency.ETH))
Assert.That(proposal.DestinationAddress,
Is.EqualTo("0xd2FDFA29D5ccbb8168Ba248D59dED7a25396f84E"))
Assert.That(proposal.OriginAddress,
Is.EqualTo("0xc295DDB9B89AFb7B0b23cFb76cb34ce33bc854D5"))

// Validate generated metadata
let etherTxMetadata =
Account.GetTransactionMetadata deserializedSignedTrans
|> Async.RunSynchronously
:?> Ether.TransactionMetadata

Assert.That(etherTxMetadata.TransactionCount, Is.EqualTo(1))
Assert.That(etherTxMetadata.Fee.Currency,
Is.EqualTo(Currency.ETC))
Is.EqualTo(Currency.ETH))
Assert.That(etherTxMetadata.Fee.GasPriceInWei,
Is.EqualTo(6969))
Assert.That(deserializedSignedTrans.TransactionInfo.Metadata.FeeEstimationTime,
Is.EqualTo MarshallingData.SomeDate)

Assert.That(deserializedSignedTrans.TransactionInfo.Cache.Balances.Count,
Is.EqualTo(2))
Assert.That(deserializedSignedTrans.TransactionInfo.Cache.UsdPrice.Count,
Is.EqualTo(2))
Is.EqualTo(6932351540UL))

[<Test>]
member __.``unsigned SAI transaction import``() =
Expand Down Expand Up @@ -204,46 +186,48 @@ type Deserialization() =
Assert.That(deserializedUnsignedTrans.Cache.UsdPrice.Count, Is.EqualTo(5))

[<Test>]
member __.``signed SAI transaction import``() =
member __.``signed DAI transaction import``() =

let deserializedSignedTrans: SignedTransaction<IBlockchainFeeInfo> =
let deserializedSignedTrans: SignedTransaction =
Account.ImportSignedTransactionFromJson
MarshallingData.SignedSaiTransactionExampleInJson
MarshallingData.SignedDaiTransactionExampleInJson

// Validate deserialized SignedTransaction
Assert.That(deserializedSignedTrans, Is.Not.Null)

Assert.That(deserializedSignedTrans.RawTransaction,
Is.EqualTo("f8a80784c74d93708291b29489d24a6b4ccb1b6faa2625fe562bdd9a2326035980b844a9059cbb000000000000000000000000db0381b1a380d8db2724a9ca2d33e0c6c044be3b0000000000000000000000000000000000000000000000000de0b6b3a764000026a072cdeb03affd5977c76366efbc1405fbb4fa997ce72c1e4554ba9ec5ef772ddca069d522ea304efebd2537330870bc1ca9e9a6fe3eb5f8d8f66c1b82d9fc27a4bf"))
Is.EqualTo("f8a90185016c653675828792946b175474e89094c44da98b954eedeac495271d0f80b844a9059cbb000000000000000000000000d2fdfa29d5ccbb8168ba248d59ded7a25396f84e0000000000000000000000000000000000000000000000000de0b6b3a764000026a0d5c49133f38f3b60aa41747a4b7cc300a6dac87803b82ba23af9a97fd5994c3ea03122864fd6b294a3da2f3827e70fa861838a168f6533e03587358a6bdc594235"))

Assert.That(deserializedSignedTrans.TransactionInfo, Is.Not.Null)
Assert.That(deserializedSignedTrans.TransactionInfo.Proposal, Is.Not.Null)
Assert.That(deserializedSignedTrans.TransactionInfo.Cache, Is.Not.Null)
Assert.That(deserializedSignedTrans.TransactionInfo.Metadata, Is.Not.Null)

Assert.That(deserializedSignedTrans.TransactionInfo.Proposal.Amount.ValueToSend,
Is.EqualTo(1m))
Assert.That(deserializedSignedTrans.TransactionInfo.Proposal.Amount.BalanceAtTheMomentOfSending,
Is.EqualTo 7.08m)
Assert.That(deserializedSignedTrans.TransactionInfo.Proposal.Amount.Currency,
Is.EqualTo Currency.SAI)
Assert.That(deserializedSignedTrans.TransactionInfo.Proposal.DestinationAddress,
Is.EqualTo("0xDb0381B1a380d8db2724A9Ca2d33E0C6C044bE3b"))
Assert.That(deserializedSignedTrans.TransactionInfo.Proposal.OriginAddress,
Is.EqualTo("0xba766d6d13E2Cc921Bf6e896319D32502af9e37E"))

let etherTxMetadata = deserializedSignedTrans.TransactionInfo.Metadata :?> Ether.TransactionMetadata
Assert.That(etherTxMetadata.TransactionCount, Is.EqualTo(7))
Assert.That(deserializedSignedTrans.Currency,
Is.EqualTo Currency.DAI)

Assert.That(deserializedSignedTrans.FeeCurrency,
Is.EqualTo(Currency.ETH))

// Validate generated proposal
let proposal = Account.GetTransactionProposal deserializedSignedTrans

Assert.That(proposal.Amount.ValueToSend,
Is.EqualTo(1.0m))
Assert.That(proposal.Amount.Currency,
Is.EqualTo(Currency.DAI))
Assert.That(proposal.DestinationAddress,
Is.EqualTo("0xd2FDFA29D5ccbb8168Ba248D59dED7a25396f84E"))
Assert.That(proposal.OriginAddress,
Is.EqualTo("0xc295DDB9B89AFb7B0b23cFb76cb34ce33bc854D5"))

// Validate generated metadata
let etherTxMetadata =
Account.GetTransactionMetadata deserializedSignedTrans
|> Async.RunSynchronously
:?> Ether.TransactionMetadata

Assert.That(etherTxMetadata.TransactionCount, Is.EqualTo(1))
Assert.That(etherTxMetadata.Fee.Currency,
Is.EqualTo(Currency.ETH))
Assert.That(etherTxMetadata.Fee.GasPriceInWei,
Is.EqualTo(3343750000L))
Assert.That(deserializedSignedTrans.TransactionInfo.Metadata.FeeEstimationTime,
Is.EqualTo MarshallingData.SomeDate)
Is.EqualTo(6113539701UL))

Assert.That(deserializedSignedTrans.TransactionInfo.Cache.Balances.Count,
Is.EqualTo 5)
Assert.That(deserializedSignedTrans.TransactionInfo.Cache.UsdPrice.Count,
Is.EqualTo(5))

[<Test>]
member __.``can roundtrip currency``() =
Expand Down
2 changes: 1 addition & 1 deletion src/GWallet.Backend.Tests/GWallet.Backend.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<EmbeddedResource Include="data\fullException_unixLegacy.json" />
<EmbeddedResource Include="data\fullException_windowsLegacy.json" />
<EmbeddedResource Include="data\signedAndFormattedBtcTransaction.json" />
<EmbeddedResource Include="data\signedAndFormattedSaiTransaction.json" />
<EmbeddedResource Include="data\signedAndFormattedDaiTransaction.json" />
<EmbeddedResource Include="data\innerException.json" />
</ItemGroup>
</Project>
19 changes: 11 additions & 8 deletions src/GWallet.Backend.Tests/MarshallingData.fs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ module MarshallingData =
let UnsignedSaiTransactionExampleInJson =
ReadEmbeddedResource "unsignedAndFormattedSaiTransaction.json"

let SignedSaiTransactionExampleInJson =
ReadEmbeddedResource "signedAndFormattedSaiTransaction.json"
let SignedDaiTransactionExampleInJson =
ReadEmbeddedResource "signedAndFormattedDaiTransaction.json"

let BasicExceptionExampleInJson =
ReadEmbeddedResource "basicException.json"
Expand Down Expand Up @@ -257,7 +257,8 @@ module MarshallingData =

let SignedBtcTransactionExample =
{
TransactionInfo = UnsignedBtcTransactionExample;
Currency = Currency.BTC
FeeCurrency = Currency.BTC
RawTransaction = "0200000000010111b6e0460bb810b05744f8d38262f95fbab02b168b070598a6f31fad438fced4000000001716001427c106013c0042da165c082b3870c31fb3ab4683feffffff0200ca9a3b0000000017a914d8b6fcc85a383261df05423ddf068a8987bf0287873067a3fa0100000017a914d5df0b9ca6c0e1ba60a9ff29359d2600d9c6659d870247304402203b85cb05b43cc68df72e2e54c6cb508aa324a5de0c53f1bbfe997cbd7509774d022041e1b1823bdaddcd6581d7cde6e6a4c4dbef483e42e59e04dbacbaf537c3e3e8012103fbbdb3b3fc3abbbd983b20a557445fb041d6f21cc5977d2121971cb1ce5298978c000000";
}

Expand Down Expand Up @@ -303,10 +304,11 @@ module MarshallingData =
Cache = realCachingDataExample;
Metadata = someSaiTxMetadata
}
let SignedSaiTransactionExample =
let SignedDaiTransactionExample =
{
TransactionInfo = someSaiTransactionInfo
RawTransaction = "f8a80784c74d93708291b29489d24a6b4ccb1b6faa2625fe562bdd9a2326035980b844a9059cbb000000000000000000000000db0381b1a380d8db2724a9ca2d33e0c6c044be3b0000000000000000000000000000000000000000000000000de0b6b3a764000026a072cdeb03affd5977c76366efbc1405fbb4fa997ce72c1e4554ba9ec5ef772ddca069d522ea304efebd2537330870bc1ca9e9a6fe3eb5f8d8f66c1b82d9fc27a4bf";
Currency = Currency.DAI
FeeCurrency = Currency.ETH
RawTransaction = "f8a90185016c653675828792946b175474e89094c44da98b954eedeac495271d0f80b844a9059cbb000000000000000000000000d2fdfa29d5ccbb8168ba248d59ded7a25396f84e0000000000000000000000000000000000000000000000000de0b6b3a764000026a0d5c49133f38f3b60aa41747a4b7cc300a6dac87803b82ba23af9a97fd5994c3ea03122864fd6b294a3da2f3827e70fa861838a168f6533e03587358a6bdc594235";
}

let someEtherTransactionInfo =
Expand All @@ -317,8 +319,9 @@ module MarshallingData =
}
let SignedEtherTransactionExample =
{
TransactionInfo = someEtherTransactionInfo;
RawTransaction = "doijfsoifjdosisdjfomirmjosmi";
Currency = Currency.ETH
FeeCurrency = Currency.ETH
RawTransaction = "f86b0185019d334a3482520894d2fdfa29d5ccbb8168ba248d59ded7a25396f84e87022a8ad81f98768026a06bb7c1f8f2b40ed2bc3a3b572cdde7fddb42a8d43c561c60580183b0ed8c2d9fa035183359feab8789642135a253371f80781f4a870f0cae8a7368c5d7e102a688";
}
let SignedEtherTransactionExampleInJson =
ReadEmbeddedResource "signedAndFormattedEtherTransaction.json"
Expand Down
8 changes: 4 additions & 4 deletions src/GWallet.Backend.Tests/Serialization.fs
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ type Serialization() =

[<Test>]
member __.``signed SAI transaction export``() =
let json = Account.ExportUnsignedTransactionToJson MarshallingData.SignedSaiTransactionExample
let json = Account.ExportUnsignedTransactionToJson MarshallingData.SignedDaiTransactionExample
Assert.That(json, Is.Not.Null)
Assert.That(json, Is.Not.Empty)
Assert.That(json|> MarshallingData.Sanitize,
Is.EqualTo MarshallingData.SignedSaiTransactionExampleInJson)
Is.EqualTo MarshallingData.SignedDaiTransactionExampleInJson)

[<Test>]
member __.``can serialize exceptions``() =
let json = Account.ExportUnsignedTransactionToJson MarshallingData.SignedSaiTransactionExample
let json = Account.ExportUnsignedTransactionToJson MarshallingData.SignedDaiTransactionExample
Assert.That(json, Is.Not.Null)
Assert.That(json, Is.Not.Empty)
Assert.That(json|> MarshallingData.Sanitize,
Is.EqualTo MarshallingData.SignedSaiTransactionExampleInJson)
Is.EqualTo MarshallingData.SignedDaiTransactionExampleInJson)
Original file line number Diff line number Diff line change
@@ -1,65 +1,12 @@
{
"Version": "{version}",
"TypeName": "GWallet.Backend.SignedTransaction`1[[GWallet.Backend.UtxoCoin.TransactionMetadata, GWallet.Backend, Version={version}, Culture=neutral, PublicKeyToken=null]]",
"TypeName": "GWallet.Backend.SignedTransaction",
"Value": {
"TransactionInfo": {
"Proposal": {
"OriginAddress": "16pKBjGGZkUXo1afyBNf5ttFvV9hauS1kR",
"Amount": {
"ValueToSend": 10.01,
"BalanceAtTheMomentOfSending": 12.02,
"Currency": {
"Case": "BTC"
}
},
"DestinationAddress": "13jxHQDxGto46QhjFiMb78dZdys9ZD8vW5"
},
"Metadata": {
"Fee": {
"EstimatedFeeInSatoshis": 10,
"EstimationTime": "2018-06-14T16:50:09.133411Z",
"Currency": {
"Case": "BTC"
}
},
"Inputs": [
{
"TransactionHash": "4d129e98d87fab00a99ebc88688752b588ec7d38c2ba5dc86d3563a6bc4c691f",
"OutputIndex": 1,
"ValueInSatoshis": 1000,
"DestinationInHex": "a9145131075257d8b8de8298e7c52891eb4b87823b9387"
}
]
},
"Cache": {
"UsdPrice": {
"BTC": 9156.19,
"ETC": 19.8644,
"ETH": 691.52,
"LTC": 173.592,
"SAI": 1.00376
},
"Addresses": {
"0xba766d6d13E2Cc921Bf6e896319D32502af9e37E": [
"ETH",
"SAI",
"ETC"
],
"3Buz1evVsQeHtDfQAmwfAKQsUzAt3f4TuR": [
"BTC"
],
"MJ88KYLTpXVigiwJGevzyxfGogmKx7WiWm": [
"LTC"
]
},
"Balances": {
"BTC": 0.0,
"ETC": 8.0,
"ETH": 7.08,
"LTC": 0.0,
"SAI": 1.0
}
}
"FeeCurrency": {
"Case": "BTC"
},
"Currency": {
"Case": "BTC"
},
"RawTransaction": "0200000000010111b6e0460bb810b05744f8d38262f95fbab02b168b070598a6f31fad438fced4000000001716001427c106013c0042da165c082b3870c31fb3ab4683feffffff0200ca9a3b0000000017a914d8b6fcc85a383261df05423ddf068a8987bf0287873067a3fa0100000017a914d5df0b9ca6c0e1ba60a9ff29359d2600d9c6659d870247304402203b85cb05b43cc68df72e2e54c6cb508aa324a5de0c53f1bbfe997cbd7509774d022041e1b1823bdaddcd6581d7cde6e6a4c4dbef483e42e59e04dbacbaf537c3e3e8012103fbbdb3b3fc3abbbd983b20a557445fb041d6f21cc5977d2121971cb1ce5298978c000000"
}
Expand Down
Loading

0 comments on commit b7a8d1e

Please sign in to comment.