Skip to content

Commit

Permalink
refactor: integration tests use TTLer/Noncer method
Browse files Browse the repository at this point in the history
  • Loading branch information
randomshinichi committed Nov 11, 2019
1 parent 0d4c9b1 commit 87f5777
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 50 deletions.
18 changes: 8 additions & 10 deletions integration_test/aens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ func randomName(length int) string {
func TestAENSWorkflow(t *testing.T) {
node := setupNetwork(t, privatenetURL, false)
alice, bob := setupAccounts(t)
aensAlice := aeternity.NewContextFromNode(node, alice.Address)
ttler, noncer, ttlnoncer := transactions.GenerateTTLNoncer(node)

name := randomName(int(config.Client.Names.NameAuctionMaxLength + 1))
// Preclaim the name
preclaimTx, nameSalt, err := aensAlice.NamePreclaimTx(name, config.Client.Fee)
preclaimTx, nameSalt, err := transactions.NewNamePreclaimTx(alice.Address, name, ttlnoncer)
if err != nil {
t.Fatal(err)
}
Expand All @@ -55,7 +55,7 @@ func TestAENSWorkflow(t *testing.T) {

// Claim the name
nameFee := transactions.CalculateMinNameFee(name)
claimTx, err := aensAlice.NameClaimTx(name, nameSalt, nameFee, config.Client.Fee)
claimTx, err := transactions.NewNameClaimTx(alice.Address, name, nameSalt, nameFee, ttlnoncer)
if err != nil {
t.Fatal(err)
}
Expand All @@ -74,7 +74,7 @@ func TestAENSWorkflow(t *testing.T) {
delay(printNameEntry)

// Update the name, make it point to something
updateTx, err := aensAlice.NameUpdateTx(name, alice.Address)
updateTx, err := transactions.NewNameUpdateTx(alice.Address, name, []string{alice.Address}, config.Client.Names.ClientTTL, ttler, noncer)
if err != nil {
t.Fatal(err)
}
Expand All @@ -91,7 +91,7 @@ func TestAENSWorkflow(t *testing.T) {
}

// Transfer the name to a recipient
transferTx, err := aensAlice.NameTransferTx(name, bob.Address)
transferTx, err := transactions.NewNameTransferTx(alice.Address, name, bob.Address, ttlnoncer)
if err != nil {
t.Fatal(err)
}
Expand All @@ -102,9 +102,7 @@ func TestAENSWorkflow(t *testing.T) {
}

// Receiver updates the name, makes it point to himself
aensBob := aeternity.NewContextFromNode(node, bob.Address)

updateTx2, err := aensBob.NameUpdateTx(name, bob.Address)
updateTx2, err := transactions.NewNameUpdateTx(bob.Address, name, []string{bob.Address}, config.Client.Names.ClientTTL, ttler, noncer)
if err != nil {
t.Fatal(err)
}
Expand All @@ -115,7 +113,7 @@ func TestAENSWorkflow(t *testing.T) {
}

// Revoke the name - shouldn't work because it is signed by the sender, who no longer owns the address
revokeTx, err := aensAlice.NameRevokeTx(name)
revokeTx, err := transactions.NewNameRevokeTx(alice.Address, name, ttlnoncer)
if err != nil {
t.Fatal(err)
}
Expand All @@ -130,7 +128,7 @@ func TestAENSWorkflow(t *testing.T) {
}

// Revoke the name - signed by the recipient
revokeTx2, err := aensBob.NameRevokeTx(name)
revokeTx2, err := transactions.NewNameRevokeTx(bob.Address, name, ttlnoncer)
if err != nil {
t.Fatal(err)
}
Expand Down
39 changes: 19 additions & 20 deletions integration_test/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/aeternity/aepp-sdk-go/v6/naet"
"github.com/aeternity/aepp-sdk-go/v6/swagguard/node/models"
"github.com/aeternity/aepp-sdk-go/v6/transactions"
"github.com/aeternity/aepp-sdk-go/v6/utils"
rlp "github.com/randomshinichi/rlpae"
)

Expand Down Expand Up @@ -112,23 +111,23 @@ func TestMain(m *testing.M) {
func TestAPI(t *testing.T) {
privateNet := setupNetwork(t, privatenetURL, false)
testNet := setupNetwork(t, testnetURL, false)
ttler, noncer, ttlnoncer := transactions.GenerateTTLNoncer(privateNet)

alice, bob := setupAccounts(t)

name := randomName(int(config.Client.Names.NameAuctionMaxLength + 1))
ctxAlice := aeternity.NewContextFromNode(privateNet, alice.Address)
ctxBob := aeternity.NewContextFromNode(privateNet, bob.Address)

// SpendTx
fmt.Println("SpendTx")
spendTx, err := ctxAlice.SpendTx(sender, bob.Address, big.NewInt(1000), config.Client.Fee, []byte(""))
spendTx, err := transactions.NewSpendTx(alice.Address, bob.Address, big.NewInt(1000), []byte(""), ttlnoncer)
if err != nil {
t.Fatal(err)
}
_, _, _ = signBroadcastWaitKeepTrackOfTx(t, spendTx, alice, privateNet)

// NamePreClaimTx
fmt.Println("NamePreClaimTx")
preclaimTx, salt, err := ctxAlice.NamePreclaimTx(name, config.Client.Fee)
preclaimTx, salt, err := transactions.NewNamePreclaimTx(alice.Address, name, ttlnoncer)
if err != nil {
t.Fatal(err)
}
Expand All @@ -137,31 +136,31 @@ func TestAPI(t *testing.T) {
// NameClaimTx
fmt.Println("NameClaimTx")
nameFee := transactions.CalculateMinNameFee(name)
claimTx, err := ctxAlice.NameClaimTx(name, salt, nameFee, config.Client.Fee)
claimTx, err := transactions.NewNameClaimTx(alice.Address, name, salt, nameFee, ttlnoncer)
if err != nil {
t.Fatal(err)
}
_, _, _ = signBroadcastWaitKeepTrackOfTx(t, claimTx, alice, privateNet)

// NameUpdateTx
fmt.Println("NameUpdateTx")
updateTx, err := ctxAlice.NameUpdateTx(name, alice.Address)
updateTx, err := transactions.NewNameUpdateTx(alice.Address, name, []string{alice.Address}, config.Client.Names.ClientTTL, ttler, noncer)
if err != nil {
t.Fatal(err)
}
_, _, _ = signBroadcastWaitKeepTrackOfTx(t, updateTx, alice, privateNet)

// NameTransferTx
fmt.Println("NameTransferTx")
transferTx, err := ctxAlice.NameTransferTx(name, bob.Address)
transferTx, err := transactions.NewNameTransferTx(alice.Address, name, bob.Address, ttlnoncer)
if err != nil {
t.Fatal(err)
}
_, _, _ = signBroadcastWaitKeepTrackOfTx(t, transferTx, alice, privateNet)

// NameRevokeTx
fmt.Println("NameRevokeTx")
revokeTx, err := ctxBob.NameRevokeTx(name)
revokeTx, err := transactions.NewNameRevokeTx(bob.Address, name, ttlnoncer)
if err != nil {
t.Fatal(err)
}
Expand All @@ -170,7 +169,7 @@ func TestAPI(t *testing.T) {
sentTxs.name = randomName(int(config.Client.Names.NameAuctionMaxLength + 2))
// NamePreClaimTx
fmt.Println("NamePreClaimTx 2nd name for other tests")
preclaimTx, salt, err = ctxAlice.NamePreclaimTx(sentTxs.name, config.Client.Fee)
preclaimTx, salt, err = transactions.NewNamePreclaimTx(alice.Address, sentTxs.name, ttlnoncer)
if err != nil {
t.Fatal(err)
}
Expand All @@ -179,15 +178,15 @@ func TestAPI(t *testing.T) {
// NameClaimTx
fmt.Println("NameClaimTx 2nd name for other tests")
nameFee2 := transactions.CalculateMinNameFee(sentTxs.name)
claimTx, err = ctxAlice.NameClaimTx(sentTxs.name, salt, nameFee2, config.Client.Fee)
claimTx, err = transactions.NewNameClaimTx(alice.Address, sentTxs.name, salt, nameFee2, ttlnoncer)
if err != nil {
t.Fatal(err)
}
_, _, _ = signBroadcastWaitKeepTrackOfTx(t, claimTx, alice, privateNet)

// OracleRegisterTx
fmt.Println("OracleRegisterTx")
register, err := ctxAlice.OracleRegisterTx("hello", "helloback", big.NewInt(1000), uint64(0), uint64(100), 0)
register, err := transactions.NewOracleRegisterTx(alice.Address, "hello", "helloback", config.Client.Oracles.QueryFee, config.OracleTTLTypeDelta, config.Client.Oracles.OracleTTLValue, config.Client.Oracles.ABIVersion, ttlnoncer)
if err != nil {
t.Fatal(err)
}
Expand All @@ -196,15 +195,15 @@ func TestAPI(t *testing.T) {
// OracleExtendTx
fmt.Println("OracleExtendTx")
sentTxs.oracleID = strings.Replace(alice.Address, "ak_", "ok_", 1)
extend, err := ctxAlice.OracleExtendTx(sentTxs.oracleID, 0, 1000)
extend, err := transactions.NewOracleExtendTx(alice.Address, sentTxs.oracleID, config.OracleTTLTypeDelta, config.Client.Oracles.QueryTTLValue, ttlnoncer)
if err != nil {
t.Fatal(err)
}
_, _, _ = signBroadcastWaitKeepTrackOfTx(t, extend, alice, privateNet)

// OracleQueryTx
fmt.Println("OracleQueryTx")
query, err := ctxAlice.OracleQueryTx(sentTxs.oracleID, "How was your day?", big.NewInt(1000), 0, 100, 0, 100)
query, err := transactions.NewOracleQueryTx(alice.Address, sentTxs.oracleID, "How was your day?", config.Client.Oracles.QueryFee, config.OracleTTLTypeDelta, config.Client.Oracles.QueryTTLValue, config.OracleTTLTypeDelta, config.Client.Oracles.ResponseTTLValue, ttlnoncer)
if err != nil {
t.Fatal(err)
}
Expand All @@ -221,14 +220,14 @@ func TestAPI(t *testing.T) {
}
delay(getOracleQueries)
oqID := oracleQueries.OracleQueries[0].ID
respond, err := ctxAlice.OracleRespondTx(sentTxs.oracleID, *oqID, "My day was fine thank you", 0, 100)
respond, err := transactions.NewOracleRespondTx(alice.Address, sentTxs.oracleID, *oqID, "My day was fine thank you", config.OracleTTLTypeDelta, config.Client.Oracles.ResponseTTLValue, ttlnoncer)
_, _, _ = signBroadcastWaitKeepTrackOfTx(t, respond, alice, privateNet)

// ContractCreateTx
fmt.Println("ContractCreateTx")
ctCreateBytecode := golden.Get(t, "identity_bytecode.txt")
ctCreateInitCalldata := golden.Get(t, "identity_initcalldata.txt")
ctCreate, err := ctxAlice.ContractCreateTx(string(ctCreateBytecode), string(ctCreateInitCalldata), config.Client.Contracts.VMVersion, config.Client.Contracts.ABIVersion, config.Client.Contracts.Deposit, config.Client.Contracts.Amount, utils.NewIntFromUint64(1e5), utils.NewIntFromUint64(564480000000000))
ctCreateBytecode := string(golden.Get(t, "identity_bytecode.txt"))
ctCreateInitCalldata := string(golden.Get(t, "identity_initcalldata.txt"))
ctCreate, err := transactions.NewContractCreateTx(alice.Address, ctCreateBytecode, config.Client.Contracts.VMVersion, config.Client.Contracts.ABIVersion, config.Client.Contracts.Deposit, config.Client.Contracts.Amount, config.Client.Contracts.GasLimit, config.Client.GasPrice, ctCreateInitCalldata, ttlnoncer)
if err != nil {
t.Fatal(err)
}
Expand All @@ -241,8 +240,8 @@ func TestAPI(t *testing.T) {

// ContractCallTx
fmt.Println("ContractCallTx")
ctCallCalldata := golden.Get(t, "identity_main42.txt")
ctCall, err := ctxAlice.ContractCallTx(sentTxs.contractID, string(ctCallCalldata), config.Client.Contracts.ABIVersion, config.Client.Contracts.Amount, utils.NewIntFromUint64(1e5), config.Client.GasPrice, utils.NewIntFromUint64(665480000000000))
ctCallCalldata := string(golden.Get(t, "identity_main42.txt"))
ctCall, err := transactions.NewContractCallTx(alice.Address, sentTxs.contractID, config.Client.Contracts.Amount, config.Client.Contracts.GasLimit, config.Client.GasPrice, config.Client.Contracts.ABIVersion, ctCallCalldata, ttlnoncer)
if err != nil {
t.Fatal(err)
}
Expand Down
8 changes: 4 additions & 4 deletions integration_test/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import (

"github.com/aeternity/aepp-sdk-go/v6/aeternity"
"github.com/aeternity/aepp-sdk-go/v6/config"
"github.com/aeternity/aepp-sdk-go/v6/utils"
"github.com/aeternity/aepp-sdk-go/v6/transactions"
"gotest.tools/golden"
)

func TestContracts(t *testing.T) {
alice, _ := setupAccounts(t)
node := setupNetwork(t, privatenetURL, false)
contractsAlice := aeternity.NewContextFromNode(node, alice.Address)
_, _, ttlnoncer := transactions.GenerateTTLNoncer(node)

var ctID string

identityBytecode := string(golden.Get(t, "identity_bytecode.txt"))
identityInitCalldata := string(golden.Get(t, "identity_initcalldata.txt"))
create, err := contractsAlice.ContractCreateTx(identityBytecode, identityInitCalldata, config.Client.Contracts.VMVersion, config.Client.Contracts.ABIVersion, config.Client.Contracts.Deposit, config.Client.Contracts.Amount, utils.NewIntFromUint64(1e5), utils.NewIntFromUint64(564480000000000))
create, err := transactions.NewContractCreateTx(alice.Address, identityBytecode, config.Client.Contracts.VMVersion, config.Client.Contracts.ABIVersion, config.Client.Contracts.Deposit, config.Client.Contracts.Amount, config.Client.Contracts.GasLimit, config.Client.GasPrice, identityInitCalldata, ttlnoncer)
if err != nil {
t.Fatal(err)
}
Expand All @@ -40,7 +40,7 @@ func TestContracts(t *testing.T) {
delay(getContract)

identityMain42Calldata := string(golden.Get(t, "identity_main42.txt"))
callTx, err := contractsAlice.ContractCallTx(ctID, identityMain42Calldata, config.Client.Contracts.ABIVersion, config.Client.Contracts.Amount, utils.NewIntFromUint64(1e5), config.Client.GasPrice, utils.NewIntFromUint64(665480000000000))
callTx, err := transactions.NewContractCallTx(alice.Address, ctID, config.Client.Contracts.Amount, config.Client.Contracts.GasLimit, config.Client.GasPrice, config.Client.Contracts.ABIVersion, identityMain42Calldata, ttlnoncer)
if err != nil {
t.Fatal(err)
}
Expand Down
15 changes: 10 additions & 5 deletions integration_test/oracle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,23 @@ import (
"github.com/aeternity/aepp-sdk-go/v6/aeternity"
"github.com/aeternity/aepp-sdk-go/v6/config"
"github.com/aeternity/aepp-sdk-go/v6/swagguard/node/models"
"github.com/aeternity/aepp-sdk-go/v6/transactions"
)

func TestOracleWorkflow(t *testing.T) {
alice, _ := setupAccounts(t)
node := setupNetwork(t, privatenetURL, false)
_, _, ttlnoncer := transactions.GenerateTTLNoncer(node)

// Setup temporary test account and fund it
testAccount, err := account.New()
if err != nil {
t.Fatal(err)
}
fundAccount(t, node, alice, testAccount, big.NewInt(1000000000000000000))
oracleAccount := aeternity.NewContextFromNode(node, testAccount.Address)

// Register
register, err := oracleAccount.OracleRegisterTx("hello", "helloback", config.Client.Oracles.QueryFee, config.Client.Oracles.QueryTTLType, config.Client.Oracles.QueryTTLValue, config.Client.Oracles.VMVersion)
register, err := transactions.NewOracleRegisterTx(testAccount.Address, "hello", "helloback", config.Client.Oracles.QueryFee, config.OracleTTLTypeDelta, config.Client.Oracles.OracleTTLValue, config.Client.Oracles.ABIVersion, ttlnoncer)
if err != nil {
t.Fatal(err)
}
Expand All @@ -49,7 +50,7 @@ func TestOracleWorkflow(t *testing.T) {
// Extend
// save the oracle's initial TTL so we can compare it with after OracleExtendTx
oracleTTL := oracle.TTL
extend, err := oracleAccount.OracleExtendTx(oraclePubKey, 0, 1000)
extend, err := transactions.NewOracleExtendTx(testAccount.Address, oraclePubKey, config.OracleTTLTypeDelta, config.Client.Oracles.OracleTTLValue, ttlnoncer)
if err != nil {
t.Fatal(err)
}
Expand All @@ -69,7 +70,7 @@ func TestOracleWorkflow(t *testing.T) {
}

// Query
query, err := oracleAccount.OracleQueryTx(oraclePubKey, "How was your day?", config.Client.Oracles.QueryFee, 0, 100, 0, 100)
query, err := transactions.NewOracleQueryTx(testAccount.Address, oraclePubKey, "How was your day?", config.Client.Oracles.QueryFee, 0, 100, 0, 100, ttlnoncer)
if err != nil {
t.Fatal(err)
}
Expand All @@ -91,9 +92,13 @@ func TestOracleWorkflow(t *testing.T) {
}
delay(getOracleQueries)
oqID := oracleQueries.OracleQueries[0].ID
fmt.Println(oraclePubKey, *oqID)

// Respond
respond, err := oracleAccount.OracleRespondTx(oraclePubKey, *oqID, "My day was fine thank you", 0, 100)
respond, err := transactions.NewOracleRespondTx(testAccount.Address, oraclePubKey, *oqID, "My day was fine thank you", config.OracleTTLTypeDelta, config.Client.Oracles.ResponseTTLValue, ttlnoncer)
if err != nil {
t.Fatal(err)
}
fmt.Printf("Respond %+v\n", respond)
_, _, _, _, _, err = aeternity.SignBroadcastWaitTransaction(respond, testAccount, node, networkID, config.Client.WaitBlocks)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions integration_test/spend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/aeternity/aepp-sdk-go/v6/aeternity"
"github.com/aeternity/aepp-sdk-go/v6/config"
"github.com/aeternity/aepp-sdk-go/v6/transactions"
"github.com/aeternity/aepp-sdk-go/v6/utils"
)

Expand All @@ -29,8 +30,8 @@ func TestSpendTx(t *testing.T) {
expected.Add(&bS, amount)
}

ctx := aeternity.NewContextFromNode(node, alice.Address)
tx, err := ctx.SpendTx(alice.Address, bob.Address, amount, config.Client.Fee, []byte(msg))
_, _, ttlnoncer := transactions.GenerateTTLNoncer(node)
tx, err := transactions.NewSpendTx(alice.Address, bob.Address, amount, []byte(msg), ttlnoncer)
if err != nil {
t.Error(err)
}
Expand Down
14 changes: 5 additions & 9 deletions integration_test/testsetup.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
"time"

"github.com/aeternity/aepp-sdk-go/v6/account"
"github.com/aeternity/aepp-sdk-go/v6/aeternity"
"github.com/aeternity/aepp-sdk-go/v6/config"
"github.com/aeternity/aepp-sdk-go/v6/naet"
"github.com/aeternity/aepp-sdk-go/v6/aeternity"
"github.com/aeternity/aepp-sdk-go/v6/transactions"
)

var sender = "ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi"
Expand Down Expand Up @@ -78,18 +79,13 @@ func waitForTransaction(node *naet.Node, hash string) (height uint64, microblock
}

func fundAccount(t *testing.T, node *naet.Node, source, destination *account.Account, amount *big.Int) {
ctx := aeternity.NewContextFromNode(node, source.Address)

_, _, ttlnoncer := transactions.GenerateTTLNoncer(node)
fmt.Println("Funding account", destination.Address)
tx, err := ctx.SpendTx(source.Address, destination.Address, amount, config.Client.Fee, []byte{})
if err != nil {
t.Fatal(err)
}
_, hash, _, err := aeternity.SignBroadcastTransaction(tx, source, node, networkID)
tx, err := transactions.NewSpendTx(source.Address, destination.Address, amount, []byte{}, ttlnoncer)
if err != nil {
t.Fatal(err)
}
_, _, err = waitForTransaction(node, hash)
_, _, _, _, _, err = aeternity.SignBroadcastWaitTransaction(tx, source, node, networkID, config.Client.WaitBlocks)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 87f5777

Please sign in to comment.