@@ -11,10 +11,8 @@ import ed25519swift
1111@Test ( " Payment: example " )
1212func paymentExample( ) throws {
1313 let aliceKeyPair = Ed25519 . generateKeyPair ( )
14- let alice = try addressFromPubKey ( pubKey: Data ( aliceKeyPair. publicKey) )
15- let bob = try addressFromString (
16- address: " B72WNFFEZ7EOGMQPP7ROHYS3DSLL5JW74QASYNWGZGQXWRPJECJJLJIJ2Y "
17- )
14+ let alice = try addressFromPublicKey ( publicKey: Data ( aliceKeyPair. publicKey) )
15+ let bob = " B72WNFFEZ7EOGMQPP7ROHYS3DSLL5JW74QASYNWGZGQXWRPJECJJLJIJ2Y "
1816
1917 let txn : Transaction = Transaction (
2018 transactionType: . payment,
@@ -31,21 +29,23 @@ func paymentExample() throws {
3129 )
3230
3331 let sig = Ed25519 . sign (
34- message: [ UInt8] ( try encodeTransaction ( tx : txn) ) , secretKey: aliceKeyPair. secretKey)
32+ message: [ UInt8] ( try encodeTransaction ( transaction : txn) ) , secretKey: aliceKeyPair. secretKey)
3533
36- let signedTxn = try attachSignature (
37- encodedTx : try encodeTransaction ( tx : txn) ,
34+ let signedTxn = SignedTransaction (
35+ transaction : txn,
3836 signature: Data ( sig)
3937 )
4038
41- #expect( signedTxn. count > 0 )
39+ let encodedSignedTxn = try encodeSignedTransaction ( signedTransaction: signedTxn)
40+
41+ #expect( !encodedSignedTxn. isEmpty)
4242}
4343
4444@Test ( " Payment: get encoded transaction type " )
4545func paymentGetEncodedTransactionType( ) throws {
4646 let testData = try loadTestData ( )
4747 let simplePayment = testData. simplePayment
48- let txType = try getEncodedTransactionType ( bytes : Data ( simplePayment. unsignedBytes) )
48+ let txType = try getEncodedTransactionType ( encodedTransaction : Data ( simplePayment. unsignedBytes) )
4949 #expect( txType == . payment)
5050}
5151
@@ -55,7 +55,7 @@ func paymentDecodeWithoutPrefix() throws {
5555 let simplePayment = testData. simplePayment
5656 let transaction = makeTransaction ( from: simplePayment)
5757 let bytesWithoutPrefix = Data ( simplePayment. unsignedBytes. dropFirst ( 2 ) )
58- let decoded = try decodeTransaction ( bytes : bytesWithoutPrefix)
58+ let decoded = try decodeTransaction ( encodedTx : bytesWithoutPrefix)
5959 #expect( decoded == transaction)
6060}
6161
@@ -64,7 +64,7 @@ func paymentDecodeWithPrefix() throws {
6464 let testData = try loadTestData ( )
6565 let simplePayment = testData. simplePayment
6666 let transaction = makeTransaction ( from: simplePayment)
67- let decoded = try decodeTransaction ( bytes : Data ( simplePayment. unsignedBytes) )
67+ let decoded = try decodeTransaction ( encodedTx : Data ( simplePayment. unsignedBytes) )
6868 #expect( decoded == transaction)
6969}
7070
@@ -74,10 +74,14 @@ func paymentEncodeWithSignature() throws {
7474 let simplePayment = testData. simplePayment
7575 let signature = Ed25519 . sign (
7676 message: simplePayment. unsignedBytes, secretKey: simplePayment. signingPrivateKey)
77- let signedTx = try attachSignature (
78- encodedTx: Data ( simplePayment. unsignedBytes) ,
79- signature: Data ( signature)
77+
78+ let signedTx = try encodeSignedTransaction (
79+ signedTransaction: SignedTransaction (
80+ transaction: makeTransaction ( from: simplePayment) ,
81+ signature: Data ( signature)
82+ )
8083 )
84+
8185 #expect( [ UInt8] ( signedTx) == simplePayment. signedBytes)
8286}
8387
@@ -86,6 +90,6 @@ func paymentEncode() throws {
8690 let testData = try loadTestData ( )
8791 let simplePayment = testData. simplePayment
8892 let transaction = makeTransaction ( from: simplePayment)
89- let encoded = try encodeTransaction ( tx : transaction)
93+ let encoded = try encodeTransaction ( transaction : transaction)
9094 #expect( [ UInt8] ( encoded) == simplePayment. unsignedBytes)
9195}
0 commit comments