@@ -10,82 +10,82 @@ import ed25519swift
1010
1111@Test ( " Payment: example " )
1212func paymentExample( ) throws {
13- let aliceKeyPair = Ed25519 . generateKeyPair ( )
14- let alice = try addressFromPubKey ( pubKey: Data ( aliceKeyPair. publicKey) )
15- let bob = try addressFromString (
16- address: " B72WNFFEZ7EOGMQPP7ROHYS3DSLL5JW74QASYNWGZGQXWRPJECJJLJIJ2Y "
17- )
13+ let aliceKeyPair = Ed25519 . generateKeyPair ( )
14+ let alice = try addressFromPubKey ( pubKey: Data ( aliceKeyPair. publicKey) )
15+ let bob = try addressFromString (
16+ address: " B72WNFFEZ7EOGMQPP7ROHYS3DSLL5JW74QASYNWGZGQXWRPJECJJLJIJ2Y "
17+ )
1818
19- let txn : Transaction = Transaction (
20- transactionType: . payment,
21- sender: alice,
22- fee: 1000 ,
23- firstValid: 1337 ,
24- lastValid: 1347 ,
25- genesisHash: Data ( repeating: 65 , count: 32 ) , // pretend this is a valid hash
26- genesisId: " localnet " ,
27- payment: PaymentTransactionFields (
28- receiver: bob,
29- amount: 1337
30- )
19+ let txn : Transaction = Transaction (
20+ transactionType: . payment,
21+ sender: alice,
22+ fee: 1000 ,
23+ firstValid: 1337 ,
24+ lastValid: 1347 ,
25+ genesisHash: Data ( repeating: 65 , count: 32 ) , // pretend this is a valid hash
26+ genesisId: " localnet " ,
27+ payment: PaymentTransactionFields (
28+ receiver: bob,
29+ amount: 1337
3130 )
31+ )
3232
33- let sig = Ed25519 . sign (
34- message: [ UInt8] ( try encodeTransaction ( tx: txn) ) , secretKey: aliceKeyPair. secretKey)
33+ let sig = Ed25519 . sign (
34+ message: [ UInt8] ( try encodeTransaction ( tx: txn) ) , secretKey: aliceKeyPair. secretKey)
3535
36- let signedTxn = try attachSignature (
37- encodedTx: try encodeTransaction ( tx: txn) ,
38- signature: Data ( sig)
39- )
36+ let signedTxn = try attachSignature (
37+ encodedTx: try encodeTransaction ( tx: txn) ,
38+ signature: Data ( sig)
39+ )
4040
41- #expect( signedTxn. count > 0 )
41+ #expect( signedTxn. count > 0 )
4242}
4343
4444@Test ( " Payment: get encoded transaction type " )
4545func paymentGetEncodedTransactionType( ) throws {
46- let testData = try loadTestData ( )
47- let simplePayment = testData. simplePayment
48- let txType = try getEncodedTransactionType ( bytes: Data ( simplePayment. unsignedBytes) )
49- #expect( txType == . payment)
46+ let testData = try loadTestData ( )
47+ let simplePayment = testData. simplePayment
48+ let txType = try getEncodedTransactionType ( bytes: Data ( simplePayment. unsignedBytes) )
49+ #expect( txType == . payment)
5050}
5151
5252@Test ( " Payment: decode without prefix " )
5353func paymentDecodeWithoutPrefix( ) throws {
54- let testData = try loadTestData ( )
55- let simplePayment = testData. simplePayment
56- let transaction = makeTransaction ( from: simplePayment)
57- let bytesWithoutPrefix = Data ( simplePayment. unsignedBytes. dropFirst ( 2 ) )
58- let decoded = try decodeTransaction ( bytes: bytesWithoutPrefix)
59- #expect( decoded == transaction)
54+ let testData = try loadTestData ( )
55+ let simplePayment = testData. simplePayment
56+ let transaction = makeTransaction ( from: simplePayment)
57+ let bytesWithoutPrefix = Data ( simplePayment. unsignedBytes. dropFirst ( 2 ) )
58+ let decoded = try decodeTransaction ( bytes: bytesWithoutPrefix)
59+ #expect( decoded == transaction)
6060}
6161
6262@Test ( " Payment: decode with prefix " )
6363func paymentDecodeWithPrefix( ) throws {
64- let testData = try loadTestData ( )
65- let simplePayment = testData. simplePayment
66- let transaction = makeTransaction ( from: simplePayment)
67- let decoded = try decodeTransaction ( bytes: Data ( simplePayment. unsignedBytes) )
68- #expect( decoded == transaction)
64+ let testData = try loadTestData ( )
65+ let simplePayment = testData. simplePayment
66+ let transaction = makeTransaction ( from: simplePayment)
67+ let decoded = try decodeTransaction ( bytes: Data ( simplePayment. unsignedBytes) )
68+ #expect( decoded == transaction)
6969}
7070
7171@Test ( " Payment: encode with signature " )
7272func paymentEncodeWithSignature( ) throws {
73- let testData = try loadTestData ( )
74- let simplePayment = testData. simplePayment
75- let signature = Ed25519 . sign (
76- message: simplePayment. unsignedBytes, secretKey: simplePayment. signingPrivateKey)
77- let signedTx = try attachSignature (
78- encodedTx: Data ( simplePayment. unsignedBytes) ,
79- signature: Data ( signature)
80- )
81- #expect( [ UInt8] ( signedTx) == simplePayment. signedBytes)
73+ let testData = try loadTestData ( )
74+ let simplePayment = testData. simplePayment
75+ let signature = Ed25519 . sign (
76+ message: simplePayment. unsignedBytes, secretKey: simplePayment. signingPrivateKey)
77+ let signedTx = try attachSignature (
78+ encodedTx: Data ( simplePayment. unsignedBytes) ,
79+ signature: Data ( signature)
80+ )
81+ #expect( [ UInt8] ( signedTx) == simplePayment. signedBytes)
8282}
8383
8484@Test ( " Payment: encode " )
8585func paymentEncode( ) throws {
86- let testData = try loadTestData ( )
87- let simplePayment = testData. simplePayment
88- let transaction = makeTransaction ( from: simplePayment)
89- let encoded = try encodeTransaction ( tx: transaction)
90- #expect( [ UInt8] ( encoded) == simplePayment. unsignedBytes)
86+ let testData = try loadTestData ( )
87+ let simplePayment = testData. simplePayment
88+ let transaction = makeTransaction ( from: simplePayment)
89+ let encoded = try encodeTransaction ( tx: transaction)
90+ #expect( [ UInt8] ( encoded) == simplePayment. unsignedBytes)
9191}
0 commit comments