diff --git a/integration_test/integration_test.go b/integration_test/integration_test.go index d215b142..ef44a711 100644 --- a/integration_test/integration_test.go +++ b/integration_test/integration_test.go @@ -2,7 +2,6 @@ package integration_test import ( "fmt" - "math/big" "os" "strings" "testing" @@ -18,6 +17,8 @@ var recipientPrivateKey = os.Getenv("INTEGRATION_TEST_RECEIVER_PRIVATE_KEY") var nodeURL = "http://localhost:3013" var networkID = "ae_docker" +// Tests for 2 things: sending an amount that is max uint64, and that the node accepts the minimum fee +// that is calculated via tx.EstimateFee(). func TestSpendTxWithNode(t *testing.T) { senderAccount, err := aeternity.AccountFromHexString(senderPrivateKey) if err != nil { @@ -30,70 +31,6 @@ func TestSpendTxWithNode(t *testing.T) { aeternity.Config.Node.NetworkID = networkID aeCli := aeternity.NewCli(aeternity.Config.Node.URL, false) - // In case this test has been run before, get recipient's account info. If it exists, expectedAmount = amount + 10 - var expectedAmount big.Int - recipientAccount, err := aeCli.APIGetAccount(recipient) - if err != nil { - expectedAmount.SetInt64(10) - } else { - expectedAmount.Add(recipientAccount.Balance.Int, big.NewInt(10)) - fmt.Printf("Recipient already exists with balance %v, expectedAmount after test is %s\n", recipientAccount.Balance.String(), expectedAmount.String()) - } - - amount := utils.NewBigInt() - amount.SetInt64(10) - fee := utils.NewBigInt() - fee.SetUint64(uint64(2e13)) - ttl, nonce, err := aeCli.GetTTLNonce(sender, aeternity.Config.Client.TTL) - if err != nil { - t.Fatalf("Error in GetTTLNonce(): %v", err) - } - - // create the SpendTransaction - tx := aeternity.NewSpendTx(sender, recipient, *amount, *fee, message, ttl, nonce) - base64TxMsg, err := aeternity.BaseEncodeTx(&tx) - if err != nil { - t.Fatalf("Base64 encoding errored out: %v", err) - } - fmt.Println(base64TxMsg) - - // sign the transaction, output params for debugging - signedBase64TxMsg, hash, signature, err := aeternity.SignEncodeTxStr(senderAccount, base64TxMsg, aeternity.Config.Node.NetworkID) - if err != nil { - t.Error(err) - } - fmt.Println(signedBase64TxMsg, hash, signature) - - // send the signed transaction to the node - err = aeCli.BroadcastTransaction(signedBase64TxMsg) - if err != nil { - t.Fatalf("Error while broadcasting transaction: %v", err) - } - - // check the recipient's balance - recipientAccount, err = aeCli.APIGetAccount(recipient) - if err != nil { - t.Fatalf("Couldn't get recipient's account data: %v", err) - } - - if recipientAccount.Balance.Cmp(&expectedAmount) != 0 { - t.Fatalf("Recipient should have %v, but has %v instead", expectedAmount.String(), recipientAccount.Balance.String()) - } -} - -func TestSpendTxLargeWithNode(t *testing.T) { - // This is a separate test because the account may not have enough funds for this test when the node has just started. - senderAccount, err := aeternity.AccountFromHexString(senderPrivateKey) - if err != nil { - t.Fatal(err) - } - recipient := "ak_Egp9yVdpxmvAfQ7vsXGvpnyfNq71msbdUpkMNYGTeTe8kPL3v" - message := "Hello World" - - aeternity.Config.Node.URL = nodeURL - aeternity.Config.Node.NetworkID = "ae_docker" - aeCli := aeternity.NewCli(aeternity.Config.Node.URL, false) - amount := utils.RequireBigIntFromString("18446744073709551615") // max uint64 fee := utils.NewBigIntFromUint64(uint64(2e13)) var expectedAmount = utils.NewBigInt() @@ -113,6 +50,11 @@ func TestSpendTxLargeWithNode(t *testing.T) { // create the SpendTransaction tx := aeternity.NewSpendTx(sender, recipient, *amount, *fee, message, ttl, nonce) + // minimize the fee to save money! + estimatedFee, _ := tx.FeeEstimate() + fmt.Println("Estimated vs Actual Fee:", estimatedFee, tx.Fee) + tx.Fee = *estimatedFee + base64TxMsg, err := aeternity.BaseEncodeTx(&tx) if err != nil { t.Fatalf("Base64 encoding errored out: %v", err)