-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathsteps_test.go
More file actions
2696 lines (2385 loc) · 76.7 KB
/
steps_test.go
File metadata and controls
2696 lines (2385 loc) · 76.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package test
import (
"bytes"
"context"
"encoding/base32"
"encoding/base64"
"encoding/gob"
"encoding/hex"
"encoding/json"
"flag"
"fmt"
"math/rand"
"os"
"path"
"reflect"
"strconv"
"strings"
"testing"
"time"
"github.com/algorand/go-algorand-sdk/v2/transaction"
"golang.org/x/crypto/ed25519"
"github.com/algorand/go-algorand-sdk/v2/abi"
"github.com/algorand/go-algorand-sdk/v2/auction"
"github.com/algorand/go-algorand-sdk/v2/client/kmd"
algodV2 "github.com/algorand/go-algorand-sdk/v2/client/v2/algod"
commonV2 "github.com/algorand/go-algorand-sdk/v2/client/v2/common"
modelsV2 "github.com/algorand/go-algorand-sdk/v2/client/v2/common/models"
indexerV2 "github.com/algorand/go-algorand-sdk/v2/client/v2/indexer"
"github.com/algorand/go-algorand-sdk/v2/crypto"
"github.com/algorand/go-algorand-sdk/v2/encoding/msgpack"
"github.com/algorand/go-algorand-sdk/v2/logic"
"github.com/algorand/go-algorand-sdk/v2/mnemonic"
"github.com/algorand/go-algorand-sdk/v2/types"
"github.com/cucumber/godog"
"github.com/cucumber/godog/colors"
)
var txn types.Transaction
var stx []byte
var stxKmd []byte
var stxObj types.SignedTxn
var txid string
var account crypto.Account
var note []byte
var fee uint64
var fv uint64
var lv uint64
var to string
var gh []byte
var close string
var amt uint64
var gen string
var a types.Address
var msig crypto.MultisigAccount
var msigsig types.MultisigSig
var kcl kmd.Client
var aclv2 *algodV2.Client
var iclv2 *indexerV2.Client
var walletName string
var walletPswd string
var walletID string
var handle string
var versions []string
var msigExp kmd.ExportMultisigResponse
var pk string
var rekey string
var accounts []string
var e bool
var lastRound uint64
var sugParams types.SuggestedParams
var bid types.Bid
var sbid types.NoteField
var oldBid types.NoteField
var oldPk string
var newMn string
var mdk types.MasterDerivationKey
var microalgos types.MicroAlgos
var bytetxs [][]byte
var votekey string
var selkey string
var stateProofPK string
var votefst uint64
var votelst uint64
var votekd uint64
var nonpart bool
var data []byte
var sig types.Signature
var abiMethod abi.Method
var abiMethods []abi.Method
var abiJsonString string
var abiInterface abi.Interface
var abiContract abi.Contract
var txComposer transaction.AtomicTransactionComposer
var accountTxSigner transaction.BasicAccountTransactionSigner
var methodArgs []interface{}
var sigTxs [][]byte
var accountTxAndSigner transaction.TransactionWithSigner
var txTrace transaction.DryrunTxnResult
var trace string
var sourceMap logic.SourceMap
var srcMapping map[string]interface{}
var seeminglyProgram []byte
var sanityCheckError error
var simulateResponse modelsV2.SimulateResponse
var assetTestFixture struct {
Creator string
AssetIndex uint64
AssetName string
AssetUnitName string
AssetURL string
AssetMetadataHash string
ExpectedParams modelsV2.AssetParams
QueriedParams modelsV2.AssetParams
LastTransactionIssued types.Transaction
}
var tealCompleResult struct {
status int
response modelsV2.CompileResponse
}
var tealDryrunResult struct {
status int
response modelsV2.DryrunResponse
}
var opt = godog.Options{
Output: colors.Colored(os.Stdout),
Format: "progress", // can define default values
}
// Dev mode helper functions
const devModeInitialAmount = 10_000_000
/**
* waitForAlgodInDevMode is a Dev mode helper method
* to wait for blocks to be finalized.
* Since Dev mode produces blocks on a per transaction basis, it's possible
* algod generates a block _before_ the corresponding SDK call to wait for a block.
* Without _any_ wait, it's possible the SDK looks for the transaction before algod completes processing.
* So, the method performs a local sleep to simulate waiting for a block.
*/
func waitForAlgodInDevMode() {
time.Sleep(500 * time.Millisecond)
}
// fundingAccount finds an account with enough funds to fund the given amount
func fundingAccount(client *algodV2.Client, amount uint64) (string, error) {
// Random shuffle to spread the load
shuffledAccounts := make([]string, len(accounts))
copy(shuffledAccounts, accounts)
rand.Shuffle(len(shuffledAccounts), func(i, j int) {
shuffledAccounts[i], shuffledAccounts[j] = shuffledAccounts[j], shuffledAccounts[i]
})
for _, accountAddress := range shuffledAccounts {
res, err := client.AccountInformation(accountAddress).Do(context.Background())
if err != nil {
return "", err
}
if res.Amount < amount+100_000 { // 100,000 microalgos is default account min balance
continue
}
return accountAddress, nil
}
return "", fmt.Errorf("no account has enough to fund %d microalgos", amount)
}
func initializeAccount(accountAddress string) error {
params, err := aclv2.SuggestedParams().Do(context.Background())
if err != nil {
return err
}
funder, err := fundingAccount(aclv2, devModeInitialAmount)
if err != nil {
return err
}
txn, err = transaction.MakePaymentTxn(funder, accountAddress, devModeInitialAmount, []byte{}, "", params)
if err != nil {
return err
}
res, err := kcl.SignTransaction(handle, walletPswd, txn)
if err != nil {
return err
}
_, err = aclv2.SendRawTransaction(res.SignedTransaction).Do(context.Background())
if err != nil {
return err
}
waitForAlgodInDevMode()
return err
}
func init() {
godog.BindFlags("godog.", flag.CommandLine, &opt)
}
func TestMain(m *testing.M) {
flag.Parse()
opt.Paths = flag.Args()
status := godog.RunWithOptions("godogs", func(s *godog.Suite) {
FeatureContext(s)
AlgodClientV2Context(s)
IndexerUnitTestContext(s)
TransactionsUnitContext(s)
ApplicationsContext(s)
ApplicationsUnitContext(s)
ResponsesContext(s)
}, opt)
if st := m.Run(); st > status {
status = st
}
os.Exit(status)
}
func FeatureContext(s *godog.Suite) {
s.Step("I create a wallet", createWallet)
s.Step("the wallet should exist", walletExist)
s.Step("I get the wallet handle", getHandle)
s.Step("I can get the master derivation key", getMdk)
s.Step("I rename the wallet", renameWallet)
s.Step("I can still get the wallet information with the same handle", getWalletInfo)
s.Step("I renew the wallet handle", renewHandle)
s.Step("I release the wallet handle", releaseHandle)
s.Step("the wallet handle should not work", tryHandle)
s.Step(`payment transaction parameters (\d+) (\d+) (\d+) "([^"]*)" "([^"]*)" "([^"]*)" (\d+) "([^"]*)" "([^"]*)"`, txnParams)
s.Step(`mnemonic for private key "([^"]*)"`, mnForSk)
s.Step(`multisig addresses "([^"]*)"`, msigAddresses)
s.Step("I create the multisig payment transaction$", createMsigTxn)
s.Step("I create the multisig payment transaction with zero fee", createMsigTxnZeroFee)
s.Step("I sign the multisig transaction with the private key", signMsigTxn)
s.Step("I sign the transaction with the private key", signTxn)
s.Step(`^I add a rekeyTo field with address "([^"]*)"$`, iAddARekeyToFieldWithAddress)
s.Step(`^I add a rekeyTo field with the private key algorand address$`, iAddARekeyToFieldWithThePrivateKeyAlgorandAddress)
s.Step(`^I set the from address to "([^"]*)"$`, iSetTheFromAddressTo)
s.Step(`the signed transaction should equal the golden "([^"]*)"`, equalGolden)
s.Step(`the multisig transaction should equal the golden "([^"]*)"`, equalMsigGolden)
s.Step(`the multisig address should equal the golden "([^"]*)"`, equalMsigAddrGolden)
s.Step("I get versions with algod", aclV)
s.Step("v1 should be in the versions", v1InVersions)
s.Step("v2 should be in the versions", v2InVersions)
s.Step("I get versions with kmd", kclV)
s.Step("I import the multisig", importMsig)
s.Step("the multisig should be in the wallet", msigInWallet)
s.Step("I export the multisig", expMsig)
s.Step("the multisig should equal the exported multisig", msigEq)
s.Step("I delete the multisig", deleteMsig)
s.Step("the multisig should not be in the wallet", msigNotInWallet)
s.Step("^I generate a key using kmd for rekeying and fund it$", genRekeyKmd)
s.Step("^I generate a key using kmd$", genKeyKmd)
s.Step("the key should be in the wallet", keyInWallet)
s.Step("I delete the key", deleteKey)
s.Step("the key should not be in the wallet", keyNotInWallet)
s.Step("I generate a key", genKey)
s.Step("I import the key", importKey)
s.Step("the private key should be equal to the exported private key", skEqExport)
s.Step("a kmd client", kmdClient)
s.Step("wallet information", walletInfo)
s.Step(`default transaction with parameters (\d+) "([^"]*)"`, defaultTxn)
s.Step(`default multisig transaction with parameters (\d+) "([^"]*)"`, defaultMsigTxn)
s.Step("I get the private key", getSk)
s.Step("I send the transaction", sendTxn)
s.Step("I send the kmd-signed transaction", sendTxnKmd)
s.Step("I send the bogus kmd-signed transaction", sendTxnKmdFailureExpected)
s.Step("I send the multisig transaction", sendMsigTxn)
s.Step("the transaction should not go through", txnFail)
s.Step("I sign the transaction with kmd", signKmd)
s.Step("the signed transaction should equal the kmd signed transaction", signBothEqual)
s.Step("I sign the multisig transaction with kmd", signMsigKmd)
s.Step("the multisig transaction should equal the kmd signed multisig transaction", signMsigBothEqual)
s.Step(`^the node should be healthy`, nodeHealth)
s.Step(`^I get the ledger supply`, ledger)
s.Step(`^I create a bid`, createBid)
s.Step(`^I encode and decode the bid`, encDecBid)
s.Step(`^the bid should still be the same`, checkBid)
s.Step(`^I decode the address`, decAddr)
s.Step(`^I encode the address`, encAddr)
s.Step(`^the address should still be the same`, checkAddr)
s.Step(`^I convert the private key back to a mnemonic`, skToMn)
s.Step(`^the mnemonic should still be the same as "([^"]*)"`, checkMn)
s.Step(`^mnemonic for master derivation key "([^"]*)"`, mnToMdk)
s.Step(`^I convert the master derivation key back to a mnemonic`, mdkToMn)
s.Step(`^I create the flat fee payment transaction`, createTxnFlat)
s.Step(`^encoded multisig transaction "([^"]*)"`, encMsigTxn)
s.Step(`^I append a signature to the multisig transaction`, appendMsig)
s.Step(`^encoded multisig transactions "([^"]*)"`, encMtxs)
s.Step(`^I merge the multisig transactions`, mergeMsig)
s.Step(`^I convert (\d+) microalgos to algos and back`, microToAlgos)
s.Step(`^it should still be the same amount of microalgos (\d+)`, checkAlgos)
s.Step("I sign the bid", signBid)
s.Step(`default V2 key registration transaction "([^"]*)"`, createKeyregWithStateProof)
s.Step(`^I can get account information`, newAccInfo)
s.Step("asset test fixture", createAssetTestFixture)
s.Step(`^default asset creation transaction with total issuance (\d+)$`, defaultAssetCreateTxn)
s.Step(`^I update the asset index$`, getAssetIndex)
s.Step(`^I get the asset info$`, getAssetInfo)
s.Step(`^I should be unable to get the asset info`, failToGetAssetInfo)
s.Step(`^the asset info should match the expected asset info$`, checkExpectedVsActualAssetParams)
s.Step(`^I create a no-managers asset reconfigure transaction$`, createNoManagerAssetReconfigure)
s.Step(`^I create an asset destroy transaction$`, createAssetDestroy)
s.Step(`^I create a transaction for a second account, signalling asset acceptance$`, createAssetAcceptanceForSecondAccount)
s.Step(`^I create a transaction transferring (\d+) assets from creator to a second account$`, createAssetTransferTransactionToSecondAccount)
s.Step(`^the creator should have (\d+) assets remaining$`, theCreatorShouldHaveAssetsRemaining)
s.Step(`^I create a freeze transaction targeting the second account$`, createFreezeTransactionTargetingSecondAccount)
s.Step(`^I create a transaction transferring (\d+) assets from a second account to creator$`, createAssetTransferTransactionFromSecondAccountToCreator)
s.Step(`^I create an un-freeze transaction targeting the second account$`, createUnfreezeTransactionTargetingSecondAccount)
s.Step(`^default-frozen asset creation transaction with total issuance (\d+)$`, defaultAssetCreateTxnWithDefaultFrozen)
s.Step(`^I create a transaction revoking (\d+) assets from a second account to creator$`, createRevocationTransaction)
s.Step(`^I create a transaction transferring <amount> assets from creator to a second account$`, iCreateATransactionTransferringAmountAssetsFromCreatorToASecondAccount) // provide handler for when godog misreads
s.Step(`^base64 encoded data to sign "([^"]*)"$`, baseEncodedDataToSign)
s.Step(`^program hash "([^"]*)"$`, programHash)
s.Step(`^I perform tealsign$`, iPerformTealsign)
s.Step(`^the signature should be equal to "([^"]*)"$`, theSignatureShouldBeEqualTo)
s.Step(`^base64 encoded program "([^"]*)"$`, baseEncodedProgram)
s.Step(`^base64 encoded private key "([^"]*)"$`, baseEncodedPrivateKey)
s.Step("an algod v2 client$", algodClientV2)
s.Step("an indexer v2 client$", indexerClientV2)
s.Step(`^I compile a teal program "([^"]*)"$`, tealCompile)
s.Step(`^it is compiled with (\d+) and "([^"]*)" and "([^"]*)"$`, tealCheckCompile)
s.Step(`^base64 decoding the response is the same as the binary "([^"]*)"$`, tealCheckCompileAgainstFile)
s.Step(`^I dryrun a "([^"]*)" program "([^"]*)"$`, tealDryrun)
s.Step(`^I get execution result "([^"]*)"$`, tealCheckDryrun)
s.Step(`^I create the Method object from method signature "([^"]*)"$`, createMethodObjectFromSignature)
s.Step(`^I serialize the Method object into json$`, serializeMethodObjectIntoJson)
s.Step(`^the produced json should equal "([^"]*)" loaded from "([^"]*)"$`, checkSerializedMethodObject)
s.Step(`^I create the Method object with name "([^"]*)" first argument type "([^"]*)" second argument type "([^"]*)" and return type "([^"]*)"$`, createMethodObjectFromProperties)
s.Step(`^I create the Method object with name "([^"]*)" first argument name "([^"]*)" first argument type "([^"]*)" second argument name "([^"]*)" second argument type "([^"]*)" and return type "([^"]*)"$`, createMethodObjectWithArgNames)
s.Step(`^I create the Method object with name "([^"]*)" method description "([^"]*)" first argument type "([^"]*)" first argument description "([^"]*)" second argument type "([^"]*)" second argument description "([^"]*)" and return type "([^"]*)"$`, createMethodObjectWithDescription)
s.Step(`^the txn count should be (\d+)$`, checkTxnCount)
s.Step(`^the method selector should be "([^"]*)"$`, checkMethodSelector)
s.Step(`^I create an Interface object from the Method object with name "([^"]*)" and description "([^"]*)"$`, createInterfaceObject)
s.Step(`^I serialize the Interface object into json$`, serializeInterfaceObjectIntoJson)
s.Step(`^I create a Contract object from the Method object with name "([^"]*)" and description "([^"]*)"$`, createContractObject)
s.Step(`^I set the Contract\'s appID to (\d+) for the network "([^"]*)"$`, iSetTheContractsAppIDToForTheNetwork)
s.Step(`^I serialize the Contract object into json$`, serializeContractObjectIntoJson)
s.Step(`^the deserialized json should equal the original Method object`, deserializeMethodJson)
s.Step(`^the deserialized json should equal the original Interface object`, deserializeInterfaceJson)
s.Step(`^the deserialized json should equal the original Contract object`, deserializeContractJson)
s.Step(`^a new AtomicTransactionComposer$`, aNewAtomicTransactionComposer)
s.Step(`^suggested transaction parameters fee (\d+), flat-fee "([^"]*)", first-valid (\d+), last-valid (\d+), genesis-hash "([^"]*)", genesis-id "([^"]*)"$`, suggestedTransactionParameters)
s.Step(`^an application id (\d+)$`, anApplicationId)
s.Step(`^I make a transaction signer for the ([^"]*) account\.$`, iMakeATransactionSignerForTheAccount)
s.Step(`^I create a new method arguments array\.$`, iCreateANewMethodArgumentsArray)
s.Step(`^I append the encoded arguments "([^"]*)" to the method arguments array\.$`, iAppendTheEncodedArgumentsToTheMethodArgumentsArray)
s.Step(`^I add a method call with the ([^"]*) account, the current application, suggested params, on complete "([^"]*)", current transaction signer, current method arguments\.$`, addMethodCall)
s.Step(`^I add a method call with the ([^"]*) account, the current application, suggested params, on complete "([^"]*)", current transaction signer, current method arguments, approval-program "([^"]*)", clear-program "([^"]*)"\.$`, addMethodCallForUpdate)
s.Step(`^I add a method call with the ([^"]*) account, the current application, suggested params, on complete "([^"]*)", current transaction signer, current method arguments, approval-program "([^"]*)", clear-program "([^"]*)", global-bytes (\d+), global-ints (\d+), local-bytes (\d+), local-ints (\d+), extra-pages (\d+)\.$`, addMethodCallForCreate)
s.Step(`^I add a nonced method call with the ([^"]*) account, the current application, suggested params, on complete "([^"]*)", current transaction signer, current method arguments\.$`, addMethodCallWithNonce)
s.Step(`^I add the nonce "([^"]*)"$`, iAddTheNonce)
s.Step(`^I build the transaction group with the composer\. If there is an error it is "([^"]*)"\.$`, buildTheTransactionGroupWithTheComposer)
s.Step(`^The composer should have a status of "([^"]*)"\.$`, theComposerShouldHaveAStatusOf)
s.Step(`^I gather signatures with the composer\.$`, iGatherSignaturesWithTheComposer)
s.Step(`^the base64 encoded signed transactions should equal "([^"]*)"$`, theBaseEncodedSignedTransactionsShouldEqual)
s.Step(`^I build a payment transaction with sender "([^"]*)", receiver "([^"]*)", amount (\d+), close remainder to "([^"]*)"$`, iBuildAPaymentTransactionWithSenderReceiverAmountCloseRemainderTo)
s.Step(`^I create a transaction with signer with the current transaction\.$`, iCreateATransactionWithSignerWithTheCurrentTransaction)
s.Step(`^I create a transaction with an empty signer with the current transaction\.$`, iCreateATransactionWithAnEmptySignerWithTheCurrentTransaction)
s.Step(`^I append the current transaction with signer to the method arguments array\.$`, iAppendTheCurrentTransactionWithSignerToTheMethodArgumentsArray)
s.Step(`^a dryrun response file "([^"]*)" and a transaction at index "([^"]*)"$`, aDryrunResponseFileAndATransactionAtIndex)
s.Step(`^calling app trace produces "([^"]*)"$`, callingAppTraceProduces)
s.Step(`^I append to my Method objects list in the case of a non-empty signature "([^"]*)"$`, iAppendToMyMethodObjectsListInTheCaseOfANonemptySignature)
s.Step(`^I create an Interface object from my Method objects list$`, iCreateAnInterfaceObjectFromMyMethodObjectsList)
s.Step(`^I create a Contract object from my Method objects list$`, iCreateAContractObjectFromMyMethodObjectsList)
s.Step(`^I get the method from the Interface by name "([^"]*)"$`, iGetTheMethodFromTheInterfaceByName)
s.Step(`^I get the method from the Contract by name "([^"]*)"$`, iGetTheMethodFromTheContractByName)
s.Step(`^the produced method signature should equal "([^"]*)"\. If there is an error it begins with "([^"]*)"$`, theProducedMethodSignatureShouldEqualIfThereIsAnErrorItBeginsWith)
s.Step(`^a source map json file "([^"]*)"$`, aSourceMapJsonFile)
s.Step(`^the string composed of pc:line number equals "([^"]*)"$`, theStringComposedOfPclineNumberEquals)
s.Step(`^I compile a teal program "([^"]*)" with mapping enabled$`, iCompileATealProgramWithMappingEnabled)
s.Step(`^the resulting source map is the same as the json "([^"]*)"$`, theResultingSourceMapIsTheSameAsTheJson)
s.Step(`^getting the line associated with a pc "([^"]*)" equals "([^"]*)"$`, gettingTheLineAssociatedWithAPcEquals)
s.Step(`^getting the last pc associated with a line "([^"]*)" equals "([^"]*)"$`, gettingTheLastPcAssociatedWithALineEquals)
s.Step(`^a base64 encoded program bytes for heuristic sanity check "([^"]*)"$`, takeB64encodedBytes)
s.Step(`^I start heuristic sanity check over the bytes$`, heuristicCheckOverBytes)
s.Step(`^if the heuristic sanity check throws an error, the error contains "([^"]*)"$`, checkErrorIfMatching)
s.Step(`^disassembly of "([^"]*)" matches "([^"]*)"$`, disassemblyMatches)
s.Step(`^I simulate the transaction$`, iSimulateTheTransaction)
s.Step(`^the simulation should succeed without any failure message$`, theSimulationShouldSucceedWithoutAnyFailureMessage)
s.Step(`^I prepare the transaction without signatures for simulation$`, iPrepareTheTransactionWithoutSignaturesForSimulation)
s.Step(`^the simulation should report a failure at group "([^"]*)", path "([^"]*)" with message "([^"]*)"$`, theSimulationShouldReportAFailureAtGroupPathWithMessage)
s.BeforeScenario(func(interface{}) {
stxObj = types.SignedTxn{}
abiMethods = nil
kcl.RenewWalletHandle(handle)
})
}
func createWallet() error {
walletName = "Walletgo"
walletPswd = ""
resp, err := kcl.CreateWallet(walletName, walletPswd, "sqlite", types.MasterDerivationKey{})
if err != nil {
return err
}
walletID = resp.Wallet.ID
return nil
}
func walletExist() error {
wallets, err := kcl.ListWallets()
if err != nil {
return err
}
for _, w := range wallets.Wallets {
if w.Name == walletName {
return nil
}
}
return fmt.Errorf("Wallet not found")
}
func getHandle() error {
h, err := kcl.InitWalletHandle(walletID, walletPswd)
if err != nil {
return err
}
handle = h.WalletHandleToken
return nil
}
func getMdk() error {
_, err := kcl.ExportMasterDerivationKey(handle, walletPswd)
return err
}
func renameWallet() error {
walletName = "Walletgo_new"
_, err := kcl.RenameWallet(walletID, walletPswd, walletName)
return err
}
func getWalletInfo() error {
resp, err := kcl.GetWallet(handle)
if resp.WalletHandle.Wallet.Name != walletName {
return fmt.Errorf("Wallet name not equal")
}
return err
}
func renewHandle() error {
_, err := kcl.RenewWalletHandle(handle)
return err
}
func releaseHandle() error {
_, err := kcl.ReleaseWalletHandle(handle)
return err
}
func tryHandle() error {
_, err := kcl.RenewWalletHandle(handle)
if err == nil {
return fmt.Errorf("should be an error; handle was released")
}
return nil
}
func iAddARekeyToFieldWithThePrivateKeyAlgorandAddress() error {
pk, err := crypto.GenerateAddressFromSK(account.PrivateKey)
if err != nil {
return err
}
err = txn.Rekey(pk.String())
if err != nil {
return err
}
return nil
}
func txnParams(ifee, ifv, ilv int, igh, ito, iclose string, iamt int, igen, inote string) error {
var err error
if inote != "none" {
note, err = base64.StdEncoding.DecodeString(inote)
if err != nil {
return err
}
} else {
note, err = base64.StdEncoding.DecodeString("")
if err != nil {
return err
}
}
gh, err = base64.StdEncoding.DecodeString(igh)
if err != nil {
return err
}
to = ito
fee = uint64(ifee)
fv = uint64(ifv)
lv = uint64(ilv)
if iclose != "none" {
close = iclose
} else {
close = ""
}
amt = uint64(iamt)
if igen != "none" {
gen = igen
} else {
gen = ""
}
if err != nil {
return err
}
return nil
}
func mnForSk(mn string) error {
sk, err := mnemonic.ToPrivateKey(mn)
if err != nil {
return err
}
account.PrivateKey = sk
var buf bytes.Buffer
enc := gob.NewEncoder(&buf)
err = enc.Encode(sk.Public())
if err != nil {
return err
}
addr := buf.Bytes()[4:]
n := copy(a[:], addr)
if n != 32 {
return fmt.Errorf("wrong address bytes length")
}
return err
}
func msigAddresses(addresses string) error {
var err error
addrlist := strings.Fields(addresses)
var addrStructs []types.Address
for _, a := range addrlist {
addr, err := types.DecodeAddress(a)
if err != nil {
return err
}
addrStructs = append(addrStructs, addr)
}
msig, err = crypto.MultisigAccountWithParams(1, 2, addrStructs)
return err
}
func iSetTheFromAddressTo(address string) error {
addr, err := types.DecodeAddress(address)
if err != nil {
return err
}
txn.Sender = addr
return nil
}
func createMsigTxn() error {
var err error
paramsToUse := types.SuggestedParams{
Fee: types.MicroAlgos(fee),
GenesisID: gen,
GenesisHash: gh,
FirstRoundValid: types.Round(fv),
LastRoundValid: types.Round(lv),
FlatFee: false,
}
msigaddr, _ := msig.Address()
txn, err = transaction.MakePaymentTxn(msigaddr.String(), to, amt, note, close, paramsToUse)
if err != nil {
return err
}
return err
}
func createMsigTxnZeroFee() error {
var err error
paramsToUse := types.SuggestedParams{
Fee: types.MicroAlgos(fee),
GenesisID: gen,
GenesisHash: gh,
FirstRoundValid: types.Round(fv),
LastRoundValid: types.Round(lv),
FlatFee: true,
}
msigaddr, _ := msig.Address()
txn, err = transaction.MakePaymentTxn(msigaddr.String(), to, amt, note, close, paramsToUse)
if err != nil {
return err
}
return err
}
func signMsigTxn() error {
var err error
txid, stx, err = crypto.SignMultisigTransaction(account.PrivateKey, msig, txn)
return err
}
func signTxn() error {
var err error
txid, stx, err = crypto.SignTransaction(account.PrivateKey, txn)
if err != nil {
return err
}
return nil
}
func iAddARekeyToFieldWithAddress(address string) error {
err := txn.Rekey(address)
if err != nil {
return err
}
return nil
}
func equalGolden(golden string) error {
goldenDecoded, err := base64.StdEncoding.DecodeString(golden)
if err != nil {
return err
}
if !bytes.Equal(goldenDecoded, stx) {
return fmt.Errorf(base64.StdEncoding.EncodeToString(stx))
}
return nil
}
func equalMsigAddrGolden(golden string) error {
msigAddr, err := msig.Address()
if err != nil {
return err
}
if golden != msigAddr.String() {
return fmt.Errorf("NOT EQUAL")
}
return nil
}
func equalMsigGolden(golden string) error {
goldenDecoded, err := base64.StdEncoding.DecodeString(golden)
if err != nil {
return err
}
if !bytes.Equal(goldenDecoded, stx) {
return fmt.Errorf("NOT EQUAL")
}
return nil
}
func aclV() error {
v, err := aclv2.Versions().Do(context.Background())
if err != nil {
return err
}
versions = v.Versions
return nil
}
func v1InVersions() error {
for _, b := range versions {
if b == "v1" {
return nil
}
}
return fmt.Errorf("v1 not found")
}
func v2InVersions() error {
for _, b := range versions {
if b == "v2" {
return nil
}
}
return fmt.Errorf("v2 not found")
}
func kclV() error {
v, err := kcl.Version()
versions = v.Versions
return err
}
func importMsig() error {
_, err := kcl.ImportMultisig(handle, msig.Version, msig.Threshold, msig.Pks)
return err
}
func msigInWallet() error {
msigs, err := kcl.ListMultisig(handle)
if err != nil {
return err
}
addrs := msigs.Addresses
for _, a := range addrs {
addr, err := msig.Address()
if err != nil {
return err
}
if a == addr.String() {
return nil
}
}
return fmt.Errorf("msig not found")
}
func expMsig() error {
addr, err := msig.Address()
if err != nil {
return err
}
msigExp, err = kcl.ExportMultisig(handle, walletPswd, addr.String())
return err
}
func msigEq() error {
eq := true
if (msig.Pks == nil) != (msigExp.PKs == nil) {
eq = false
}
if len(msig.Pks) != len(msigExp.PKs) {
eq = false
}
for i := range msig.Pks {
if !bytes.Equal(msig.Pks[i], msigExp.PKs[i]) {
eq = false
}
}
if !eq {
return fmt.Errorf("exported msig not equal to original msig")
}
return nil
}
func deleteMsig() error {
addr, err := msig.Address()
kcl.DeleteMultisig(handle, walletPswd, addr.String())
return err
}
func msigNotInWallet() error {
msigs, err := kcl.ListMultisig(handle)
if err != nil {
return err
}
addrs := msigs.Addresses
for _, a := range addrs {
addr, err := msig.Address()
if err != nil {
return err
}
if a == addr.String() {
return fmt.Errorf("msig found unexpectedly; should have been deleted")
}
}
return nil
}
func genKeyKmd() error {
p, err := kcl.GenerateKey(handle)
if err != nil {
return err
}
pk = p.Address
return nil
}
func genRekeyKmd() error {
p, err := kcl.GenerateKey(handle)
if err != nil {
return err
}
rekey = p.Address
initializeAccount(rekey)
return nil
}
func keyInWallet() error {
resp, err := kcl.ListKeys(handle)
if err != nil {
return err
}
for _, a := range resp.Addresses {
if pk == a {
return nil
}
}
return fmt.Errorf("key not found")
}
func deleteKey() error {
_, err := kcl.DeleteKey(handle, walletPswd, pk)
return err
}
func keyNotInWallet() error {
resp, err := kcl.ListKeys(handle)
if err != nil {
return err
}
for _, a := range resp.Addresses {
if pk == a {
return fmt.Errorf("key found unexpectedly; should have been deleted")
}
}
return nil
}
func genKey() error {
account = crypto.GenerateAccount()
a = account.Address
pk = a.String()
return nil
}
func importKey() error {
_, err := kcl.ImportKey(handle, account.PrivateKey)
return err
}
func skEqExport() error {
exp, err := kcl.ExportKey(handle, walletPswd, a.String())
if err != nil {
return err
}
kcl.DeleteKey(handle, walletPswd, a.String())
if bytes.Equal(exp.PrivateKey.Seed(), account.PrivateKey.Seed()) {
return nil
}
return fmt.Errorf("private keys not equal")
}
func kmdClient() error {
kmdToken := "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
kmdAddress := "http://localhost:" + "60001"
var err error
kcl, err = kmd.MakeClient(kmdAddress, kmdToken)
return err
}
func algodClientV2() error {
algodToken := "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
algodAddress := "http://localhost:" + "60000"
var err error
aclv2, err = algodV2.MakeClient(algodAddress, algodToken)
algodV2client = aclv2
if err != nil {
return err
}
_, err = aclv2.StatusAfterBlock(1).Do(context.Background())
return err
}
func indexerClientV2() error {
indexerAddress := "http://localhost:" + "59999"
var err error
iclv2, err = indexerV2.MakeClient(indexerAddress, "")
indexerV2client = iclv2
return err
}
func walletInfo() error {
walletName = "unencrypted-default-wallet"
walletPswd = ""
wallets, err := kcl.ListWallets()
if err != nil {
return err
}
for _, w := range wallets.Wallets {
if w.Name == walletName {
walletID = w.ID
}
}
h, err := kcl.InitWalletHandle(walletID, walletPswd)
if err != nil {
return err
}
handle = h.WalletHandleToken
accs, err := kcl.ListKeys(handle)
accounts = accs.Addresses
return err
}
// Helper function for making default transactions.
func defaultTxnWithAddress(iamt int, inote string, senderAddress string) error {
var err error
if inote != "none" {
note, err = base64.StdEncoding.DecodeString(inote)
if err != nil {
return err
}
} else {
note, err = base64.StdEncoding.DecodeString("")
if err != nil {
return err
}
}
amt = uint64(iamt)
pk = senderAddress
params, err := aclv2.SuggestedParams().Do(context.Background())
if err != nil {
return err
}
lastRound = uint64(params.FirstRoundValid)
txn, err = transaction.MakePaymentTxn(senderAddress, accounts[1], amt, note, "", params)
return err
}
func defaultTxn(iamt int, inote string) error {
return defaultTxnWithAddress(iamt, inote, accounts[0])
}
func defaultMsigTxn(iamt int, inote string) error {
var err error
if inote != "none" {
note, err = base64.StdEncoding.DecodeString(inote)
if err != nil {
return err
}
} else {
note, err = base64.StdEncoding.DecodeString("")
if err != nil {
return err
}
}
amt = uint64(iamt)
pk = accounts[0]
var addrStructs []types.Address
for _, a := range accounts {
addr, err := types.DecodeAddress(a)
if err != nil {
return err
}
addrStructs = append(addrStructs, addr)
}
msig, err = crypto.MultisigAccountWithParams(1, 1, addrStructs)
if err != nil {
return err
}
params, err := aclv2.SuggestedParams().Do(context.Background())
if err != nil {
return err
}
lastRound = uint64(params.FirstRoundValid)
addr, err := msig.Address()
if err != nil {
return err
}
txn, err = transaction.MakePaymentTxn(addr.String(), accounts[1], amt, note, "", params)
if err != nil {
return err
}
return nil
}
func getSk() error {
sk, err := kcl.ExportKey(handle, walletPswd, pk)
if err != nil {
return err
}
account.PrivateKey = sk.PrivateKey
return nil
}
func sendTxn() error {
tx, err := aclv2.SendRawTransaction(stx).Do(context.Background())
if err != nil {
return err
}
txid = tx
return nil
}
func sendTxnKmd() error {
var err error
txid, err = aclv2.SendRawTransaction(stxKmd).Do(context.Background())