Skip to content

Commit

Permalink
feature: integration test funding function to make tests idempotent
Browse files Browse the repository at this point in the history
  • Loading branch information
randomshinichi committed Aug 7, 2019
1 parent bd30589 commit c1f99d8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
10 changes: 8 additions & 2 deletions integration_test/ga_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package integrationtest

import (
"math/big"
"testing"

"github.com/aeternity/aepp-sdk-go/aeternity"
Expand All @@ -25,8 +26,13 @@ func TestGeneralizedAccounts(t *testing.T) {
if err != nil {
t.Fatal(err)
}
gaAlice := aeternity.NewGAAttachTx(alice.Address, 1, authBytecode, auth.TypeInfo[0].FuncHash, aeternity.Config.Client.Contracts.VMVersion, aeternity.Config.Client.Contracts.ABIVersion, aeternity.Config.Client.BaseGas, aeternity.Config.Client.GasPrice, aeternity.Config.Client.Fee, aeternity.Config.Client.TTL, authCalldata)
txHash := signBroadcast(t, &gaAlice, alice, aeNode)
testAccount, err := aeternity.NewAccount()
if err != nil {
t.Fatal(err)
}
fundAccount(t, aeNode, alice, testAccount, big.NewInt(1000000000000000000))
gaTx := aeternity.NewGAAttachTx(testAccount.Address, 1, authBytecode, auth.TypeInfo[0].FuncHash, aeternity.Config.Client.Contracts.VMVersion, aeternity.Config.Client.Contracts.ABIVersion, aeternity.Config.Client.BaseGas, aeternity.Config.Client.GasPrice, aeternity.Config.Client.Fee, aeternity.Config.Client.TTL, authCalldata)
txHash := signBroadcast(t, &gaTx, testAccount, aeNode)
_, _, err = waitForTransaction(aeNode, txHash)
if err != nil {
t.Fatal(err)
Expand Down
17 changes: 17 additions & 0 deletions integration_test/testsetup.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package integrationtest
import (
"fmt"
"io/ioutil"
"math/big"
"os"
"testing"
"time"
Expand Down Expand Up @@ -94,3 +95,19 @@ func waitForTransaction(aeNode *aeternity.Node, hash string) (height uint64, mic
fmt.Println("Transaction was found at", height, "microblockHash", microblockHash, "err", err)
return height, microblockHash, err
}

func fundAccount(t *testing.T, n *aeternity.Node, source, destination *aeternity.Account, amount *big.Int) {
h := aeternity.Helpers{Node: n}
ctx := aeternity.Context{Address: source.Address, Helpers: h}

fmt.Println("Funding account", destination.Address)
tx, err := ctx.SpendTx(source.Address, destination.Address, *amount, aeternity.Config.Client.Fee, []byte{})
if err != nil {
t.Fatal(err)
}
hash := signBroadcast(t, &tx, source, n)
_, _, err = waitForTransaction(n, hash)
if err != nil {
t.Fatal(err)
}
}

0 comments on commit c1f99d8

Please sign in to comment.