Skip to content

Commit

Permalink
feature: initial Generalized Accounts integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
randomshinichi committed Aug 7, 2019
1 parent de87f33 commit bd30589
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
14 changes: 14 additions & 0 deletions integration_test/authorize.aes
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
contract BlindAuth =
record state = { nonce : int, owner : address }

entrypoint init(owner' : address) = { nonce = 1, owner = owner' }

stateful entrypoint authorize(s : signature) : bool =
switch(Auth.tx_hash)
None => abort("Not in Auth context")
Some(tx_hash) =>
put(state{ nonce = state.nonce + 1 })
true

entrypoint to_sign(h : hash, n : int) : hash =
Crypto.blake2b((h, n))
34 changes: 34 additions & 0 deletions integration_test/ga_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package integrationtest

import (
"testing"

"github.com/aeternity/aepp-sdk-go/aeternity"
)

func TestGeneralizedAccounts(t *testing.T) {
alice, _ := setupAccounts(t)
aeNode := setupNetwork(t, privatenetURL, false)
compiler := aeternity.NewCompiler(aeternity.Config.Client.Contracts.CompilerURL, false)

authSource := readFile(t, "authorize.aes")
authBytecode, err := compiler.CompileContract(authSource)
if err != nil {
t.Fatal(err)
}
authCalldata, err := compiler.EncodeCalldata(authSource, "init", []string{alice.Address})
if err != nil {
t.Fatal(err)
}

auth, err := aeternity.NewContractFromString(authBytecode)
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)
_, _, err = waitForTransaction(aeNode, txHash)
if err != nil {
t.Fatal(err)
}
}
15 changes: 13 additions & 2 deletions integration_test/testsetup.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package integrationtest

import (
"fmt"
"io/ioutil"
"os"
"testing"
"time"
Expand Down Expand Up @@ -38,8 +39,10 @@ func setupAccounts(t *testing.T) (*aeternity.Account, *aeternity.Account) {
}

func signBroadcast(t *testing.T, tx aeternity.Tx, acc *aeternity.Account, aeNode *aeternity.Node) (hash string) {
txB64, _ := aeternity.BaseEncodeTx(tx)
// t.Log(txB64)
txB64, err := aeternity.BaseEncodeTx(tx)
if err != nil {
t.Fatal(err)
}

signedTxStr, hash, _, err := aeternity.SignEncodeTxStr(acc, txB64, aeternity.Config.Node.NetworkID)
if err != nil {
Expand All @@ -55,6 +58,14 @@ func signBroadcast(t *testing.T, tx aeternity.Tx, acc *aeternity.Account, aeNode

}

func readFile(t *testing.T, filename string) (r string) {
rb, err := ioutil.ReadFile(filename)
if err != nil {
t.Fatal(err)
}
return string(rb)
}

type delayableCode func()

func delay(f delayableCode) {
Expand Down

0 comments on commit bd30589

Please sign in to comment.