Skip to content

Commit

Permalink
aeternity_test: TestSpendTransactionWithNode integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
randomshinichi committed Feb 28, 2019
1 parent 09c2ea4 commit 084e9f3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 32 deletions.
32 changes: 0 additions & 32 deletions aeternity/api_test.go

This file was deleted.

47 changes: 47 additions & 0 deletions aeternity/helpers_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package aeternity_test

import (
"fmt"
"math/big"
"os"
"testing"

"github.com/aeternity/aepp-sdk-go/aeternity"
Expand Down Expand Up @@ -30,3 +33,47 @@ func TestSpendTransaction(t *testing.T) {
}

}

func TestSpendTransactionWithNode(t *testing.T) {
sender := "ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi"
senderPrivateKey := os.Getenv("INTEGRATION_TEST_SENDER_PRIVATE_KEY")
senderAccount, _ := aeternity.AccountFromHexString(senderPrivateKey)
recipient := "ak_Egp9yVdpxmvAfQ7vsXGvpnyfNq71msbdUpkMNYGTeTe8kPL3v"

aeternity.Config.Epoch.URL = "http://localhost:3013"
aeternity.Config.Epoch.NetworkID = "ae_docker"

// create the SpendTransaction
base64TxMsg, _, _, err := aeternity.SpendTransaction(sender, recipient, 10, 10, "")
if err != nil {
t.Errorf("SpendTransaction errored out: %v", err)
}
fmt.Println(base64TxMsg)

// sign the transaction, output params for debugging
signedBase64TxMsg, txHash, signature, err := aeternity.SignEncodeTxStr(senderAccount, base64TxMsg)
if err != nil {
t.Error(err)
}
fmt.Println(signedBase64TxMsg)
fmt.Println(txHash)
fmt.Println(signature)

// send the signed transaction to the node
err = aeternity.BroadcastTransaction(signedBase64TxMsg)
if err != nil {
t.Errorf("Error while broadcasting transaction: %v", err)
}

// check the recipient's balance
aeCli := aeternity.NewCli(aeternity.Config.Epoch.URL, false)
recipientAccount, err := aeCli.APIGetAccount(recipient)
if err != nil {
t.Errorf("Couldn't get refcipient's account data: %v", err)
}

ten := big.NewInt(10)
if recipientAccount.Balance.Cmp(ten) != 0 {
t.Errorf("Recipient should have 10AE, but has %v instead", recipientAccount.Balance.Int)
}
}

0 comments on commit 084e9f3

Please sign in to comment.