Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ unit:

integration:
go test $(TEST_SOURCES_NO_CUCUMBER)
cd test && go test -timeout 0s --godog.strict=true --godog.format=pretty --godog.tags="@algod,@assets,@auction,@kmd,@send,@indexer,@rekey,@send.keyregtxn,@dryrun,@compile,@applications.verified,@indexer.applications,@indexer.231,@abi,@c2c,@compile.sourcemap" --test.v .
cd test && go test -timeout 0s --godog.strict=true --godog.format=pretty --godog.tags="@algod,@assets,@auction,@kmd,@send,@indexer,@rekey_v1,@send.keyregtxn,@dryrun,@compile,@applications.verified,@indexer.applications,@indexer.231,@abi,@c2c,@compile.sourcemap" --test.v .

docker-test:
./test/docker/run_docker.sh
Expand Down
6 changes: 3 additions & 3 deletions test/applications_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func iCreateANewTransientAccountAndFundItWithMicroalgos(microalgos int) error {
if err != nil {
return err
}
_, err = future.WaitForConfirmation(algodV2client, ltxid, 5, context.Background())
_, err = future.WaitForConfirmation(algodV2client, ltxid, 1, context.Background())
if err != nil {
return err
}
Expand Down Expand Up @@ -99,7 +99,7 @@ func iFundTheCurrentApplicationsAddress(microalgos int) error {
return err
}

_, err = future.WaitForConfirmation(algodV2client, txid, 5, context.Background())
_, err = future.WaitForConfirmation(algodV2client, txid, 1, context.Background())
return err
}

Expand Down Expand Up @@ -266,7 +266,7 @@ func iSignAndSubmitTheTransactionSavingTheTxidIfThereIsAnErrorItIs(expectedErr s
}

func iWaitForTheTransactionToBeConfirmed() error {
_, err := future.WaitForConfirmation(algodV2client, txid, 5, context.Background())
_, err := future.WaitForConfirmation(algodV2client, txid, 1, context.Background())
if err != nil {
return err
}
Expand Down
104 changes: 92 additions & 12 deletions test/steps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"flag"
"fmt"
"io/ioutil"
"math/rand"
"os"
"path"
"reflect"
Expand Down Expand Up @@ -71,6 +72,7 @@ var status models.NodeStatus
var statusAfter models.NodeStatus
var msigExp kmd.ExportMultisigResponse
var pk string
var rekey string
var accounts []string
var e bool
var lastRound uint64
Expand Down Expand Up @@ -138,6 +140,69 @@ var opt = godog.Options{
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)
}

func initializeAccount(accountAddress string) error {
params, err := acl.BuildSuggestedParams()
if err != nil {
return err
}

txn, err = future.MakePaymentTxn(accounts[0], accountAddress, devModeInitialAmount, []byte{}, "", params)
if err != nil {
return err
}

res, err := kcl.SignTransaction(handle, walletPswd, txn)
if err != nil {
return err
}

_, err = acl.SendRawTransaction(res.SignedTransaction)
if err != nil {
return err
}
waitForAlgodInDevMode()
return err
}

func selfPayTransaction() error {
params, err := acl.BuildSuggestedParams()
if err != nil {
return err
}

txn, err = future.MakePaymentTxn(accounts[0], accounts[0], uint64(rand.Intn(devModeInitialAmount*0.01)), []byte{}, "", params)
if err != nil {
return err
}

res, err := kcl.SignTransaction(handle, walletPswd, txn)
if err != nil {
return err
}

_, err = acl.SendRawTransaction(res.SignedTransaction)
if err != nil {
return err
}
waitForAlgodInDevMode()
return err
}

func init() {
godog.BindFlags("godog.", flag.CommandLine, &opt)
}
Expand Down Expand Up @@ -199,7 +264,8 @@ func FeatureContext(s *godog.Suite) {
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", genKeyKmd)
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)
Expand Down Expand Up @@ -662,6 +728,7 @@ func getStatus() error {

func statusAfterBlock() error {
var err error
selfPayTransaction()
statusAfter, err = acl.StatusAfterBlock(lastRound)
if err != nil {
return err
Expand Down Expand Up @@ -766,6 +833,16 @@ func genKeyKmd() error {
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 {
Expand Down Expand Up @@ -876,7 +953,8 @@ func walletInfo() error {
return err
}

func defaultTxn(iamt int, inote string) error {
// 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)
Expand All @@ -891,16 +969,24 @@ func defaultTxn(iamt int, inote string) error {
}

amt = uint64(iamt)
pk = accounts[0]
pk = senderAddress
params, err := acl.BuildSuggestedParams()
if err != nil {
return err
}
lastRound = uint64(params.FirstRoundValid)
txn, err = future.MakePaymentTxn(accounts[0], accounts[1], amt, note, "", params)
txn, err = future.MakePaymentTxn(senderAddress, accounts[1], amt, note, "", params)
return err
}

func defaultTxn(iamt int, inote string) error {
return defaultTxnWithAddress(iamt, inote, accounts[0])
}

func defaultTxnRekey(iamt int, inote string) error {
return defaultTxnWithAddress(iamt, inote, rekey)
}

func defaultMsigTxn(iamt int, inote string) error {
var err error
if inote != "none" {
Expand Down Expand Up @@ -997,14 +1083,11 @@ func sendMsigTxn() error {
}

func checkTxn() error {
waitForAlgodInDevMode()
_, err := acl.PendingTransactionInformation(txid)
if err != nil {
return err
}
_, err = acl.StatusAfterBlock(lastRound + 2)
if err != nil {
return err
}
if txn.Sender.String() != "" && txn.Sender.String() != "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ" {
_, err = acl.TransactionInformation(txn.Sender.String(), txid)
} else {
Expand All @@ -1019,10 +1102,7 @@ func checkTxn() error {

func txnbyID() error {
var err error
_, err = acl.StatusAfterBlock(lastRound + 2)
if err != nil {
return err
}
waitForAlgodInDevMode()
_, err = acl.TransactionByID(txid)
return err
}
Expand Down