diff --git a/integration_test/compiler_test.go b/integration_test/compiler_test.go index 34e49e0c..d934d1da 100644 --- a/integration_test/compiler_test.go +++ b/integration_test/compiler_test.go @@ -4,10 +4,15 @@ import ( "testing" "github.com/aeternity/aepp-sdk-go/aeternity" - "github.com/aeternity/aepp-sdk-go/golden" + "gotest.tools/golden" ) func TestCompiler(t *testing.T) { + simplestorageSource := "simplestorage.aes" + simplestorageBytecode := "simplestorage_bytecode.txt" + simplestorageCalldata := "simplestorage_init42.txt" + identitySource := "identity.aes" + c := aeternity.NewCompiler("http://localhost:3080", false) t.Run("APIVersion", func(t *testing.T) { _, err := c.APIVersion() @@ -16,26 +21,27 @@ func TestCompiler(t *testing.T) { } }) t.Run("CompileContract", func(t *testing.T) { - _, err := c.CompileContract("contract Identity =\n type state = ()\n entrypoint main(z : int) = z") + compiled, err := c.CompileContract(string(golden.Get(t, simplestorageSource)), aeternity.Config.Compiler.Backend) if err != nil { t.Error(err) } + golden.Assert(t, compiled, simplestorageBytecode) }) t.Run("DecodeCallResult", func(t *testing.T) { // taken from contract_test.go - _, err := c.DecodeCallResult("ok", "cb_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACr8s/aY", "main", golden.IdentitySource) + _, err := c.DecodeCallResult("ok", "cb_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACr8s/aY", "main", string(golden.Get(t, identitySource)), aeternity.Config.Compiler.Backend) if err != nil { t.Error(err) } }) t.Run("DecodeCalldataBytecode", func(t *testing.T) { - _, err := c.DecodeCalldataBytecode(golden.SimpleStorageBytecode, golden.SimpleStorageCalldata) + _, err := c.DecodeCalldataBytecode(string(golden.Get(t, simplestorageBytecode)), string(golden.Get(t, simplestorageCalldata)), aeternity.Config.Compiler.Backend) if err != nil { t.Error(err) } }) t.Run("DecodeCalldataSource", func(t *testing.T) { - _, err := c.DecodeCalldataSource(golden.SimpleStorageSource, golden.SimpleStorageCalldata) + _, err := c.DecodeCalldataSource(string(golden.Get(t, simplestorageSource)), "init", string(golden.Get(t, simplestorageCalldata)), aeternity.Config.Compiler.Backend) if err != nil { t.Error(err) } @@ -47,14 +53,22 @@ func TestCompiler(t *testing.T) { t.Error(err) } }) - t.Run("EncodeCalldata", func(t *testing.T) { - _, err := c.EncodeCalldata(golden.SimpleStorageSource, "set", []string{"123"}) + t.Run("EncodeCalldata SimpleStorage set(123)", func(t *testing.T) { + encodedCalldata, err := c.EncodeCalldata(string(golden.Get(t, simplestorageSource)), "set", []string{"123"}, aeternity.Config.Compiler.Backend) + if err != nil { + t.Error(err) + } + golden.Assert(t, encodedCalldata, "simplestorage_set123.txt") + }) + t.Run("EncodeCalldata SimpleStorage init(42)", func(t *testing.T) { + encodedCalldata, err := c.EncodeCalldata(string(golden.Get(t, simplestorageSource)), "init", []string{"42"}, aeternity.Config.Compiler.Backend) if err != nil { t.Error(err) } + golden.Assert(t, encodedCalldata, "simplestorage_init42.txt") }) t.Run("GenerateACI", func(t *testing.T) { - _, err := c.GenerateACI(golden.SimpleStorageSource) + _, err := c.GenerateACI(string(golden.Get(t, simplestorageSource)), aeternity.Config.Compiler.Backend) if err != nil { t.Error(err) } diff --git a/integration_test/contract_test.go b/integration_test/contract_test.go index d9d62e75..c7aae89e 100644 --- a/integration_test/contract_test.go +++ b/integration_test/contract_test.go @@ -5,8 +5,8 @@ import ( "testing" "github.com/aeternity/aepp-sdk-go/aeternity" - "github.com/aeternity/aepp-sdk-go/golden" "github.com/aeternity/aepp-sdk-go/utils" + "gotest.tools/golden" ) func TestContracts(t *testing.T) { @@ -18,7 +18,9 @@ func TestContracts(t *testing.T) { var ctID string var txHash string - create, err := contractsAlice.ContractCreateTx(golden.IdentityBytecode, golden.IdentityInitCalldata, aeternity.Config.Client.Contracts.VMVersion, aeternity.Config.Client.Contracts.ABIVersion, aeternity.Config.Client.Contracts.Deposit, aeternity.Config.Client.Contracts.Amount, *utils.NewIntFromUint64(1e5), aeternity.Config.Client.Contracts.GasPrice, *utils.NewIntFromUint64(564480000000000)) + identityBytecode := string(golden.Get(t, "identity_bytecode.txt")) + identityInitCalldata := string(golden.Get(t, "identity_initcalldata.txt")) + create, err := contractsAlice.ContractCreateTx(identityBytecode, identityInitCalldata, aeternity.Config.Client.Contracts.VMVersion, aeternity.Config.Client.Contracts.ABIVersion, aeternity.Config.Client.Contracts.Deposit, aeternity.Config.Client.Contracts.Amount, *utils.NewIntFromUint64(1e5), aeternity.Config.Client.Contracts.GasPrice, *utils.NewIntFromUint64(564480000000000)) if err != nil { t.Fatal(err) } @@ -42,7 +44,8 @@ func TestContracts(t *testing.T) { } delay(getContract) - callTx, err := contractsAlice.ContractCallTx(ctID, golden.IdentityCalldata, aeternity.Config.Client.Contracts.ABIVersion, aeternity.Config.Client.Contracts.Amount, *utils.NewIntFromUint64(1e5), aeternity.Config.Client.Contracts.GasPrice, *utils.NewIntFromUint64(665480000000000)) + identityMain42Calldata := string(golden.Get(t, "identity_main42.txt")) + callTx, err := contractsAlice.ContractCallTx(ctID, identityMain42Calldata, aeternity.Config.Client.Contracts.ABIVersion, aeternity.Config.Client.Contracts.Amount, *utils.NewIntFromUint64(1e5), aeternity.Config.Client.Contracts.GasPrice, *utils.NewIntFromUint64(665480000000000)) if err != nil { t.Fatal(err) } diff --git a/integration_test/ga_test.go b/integration_test/ga_test.go index 59b1a79a..1153c65c 100644 --- a/integration_test/ga_test.go +++ b/integration_test/ga_test.go @@ -6,9 +6,9 @@ import ( "testing" "github.com/aeternity/aepp-sdk-go/aeternity" - "github.com/aeternity/aepp-sdk-go/golden" "github.com/aeternity/aepp-sdk-go/utils" rlp "github.com/randomshinichi/rlpae" + "gotest.tools/golden" ) func EncodeRLPToBytes(tx rlp.Encoder) (b []byte, err error) { @@ -37,12 +37,13 @@ func TestGeneralizedAccounts(t *testing.T) { expected.Add(&bS, amount) } + authorizeSource := string(golden.Get(t, "authorize.aes")) // Read the auth contract from a file, compile and prepare its init() calldata - authBytecode, err := compiler.CompileContract(golden.AuthorizeSource) + authBytecode, err := compiler.CompileContract(authorizeSource, aeternity.Config.Compiler.Backend) if err != nil { t.Fatal(err) } - authInitCalldata, err := compiler.EncodeCalldata(golden.AuthorizeSource, "init", []string{alice.Address}) + authInitCalldata, err := compiler.EncodeCalldata(authorizeSource, "init", []string{alice.Address}, aeternity.Config.Compiler.Backend) if err != nil { t.Fatal(err) } diff --git a/integration_test/testdata/authorize.aes b/integration_test/testdata/authorize.aes new file mode 100644 index 00000000..a4c30fbe --- /dev/null +++ b/integration_test/testdata/authorize.aes @@ -0,0 +1,10 @@ +contract BlindAuth = + record state = { owner : address } + entrypoint init(owner' : address) = { owner = owner' } + stateful entrypoint authorize(r: int) : bool = + // r is a random number only used to make tx hashes unique + switch(Auth.tx_hash) + None => abort("Not in Auth context") + Some(tx_hash) => true + entrypoint to_sign(h : hash, n : int) : hash = + Crypto.blake2b((h, n)) \ No newline at end of file diff --git a/integration_test/testdata/authorize_bytecode.txt b/integration_test/testdata/authorize_bytecode.txt new file mode 100644 index 00000000..2546b7e2 --- /dev/null +++ b/integration_test/testdata/authorize_bytecode.txt @@ -0,0 +1 @@ +cb_+QegRgKgOOZuRvAD/pZCyb5ecQ1p6GELFfi4tlz2cnV2M5iDqkL5BVH5AS+gRrV7nxBth7jGHEXDcLBgHqsprJbpyn+vdmx578COSuuJYXV0aG9yaXpluMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAoP//////////////////////////////////////////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC4QAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD5AY6g3x9QvmHUCNlWpzjYO1II0n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AAAAAAAAAAAAAAAAAAAAAAAAAABAP//////////////////////////////////////////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGA//////////////////////////////////////////8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALkCIGIAAI9iAADCkYCAgFF/RrV7nxBth7jGHEXDcLBgHqsprJbpyn+vdmx578COSusUYgAA0ldQgIBRf98fUL5h1AjZVqc42DtSCNJz9246K2XN/CAWn0QFGSjvFGIAAVNXUIBRf+IjHWzfyTkW3kyzqYV79lz0D8JW9KFJiz9+fJgMGZNEFGIAAdhXUGABGVEAW2AAGVlgIAGQgVJgIJADYABZkIFSgVJZYCABkIFSYCCQA2ADgVKQWWAAUVlSYABSYADzW2AAgFJgAPNbYAD9kFCQVltgIAFRUZBQWVCAkVBQYABgAGAAYQH0WZCBUmAAYABa8YBRYAAUYgABDVeAUWABFGIAAUZXUGABGVEAW1B/Tm90IGluIEF1dGggY29udGV4dAAAAAAAAAAAAAAAAABZYCABkIFSYCCQA2ATgVKQUGIAAMpWW2AgAVFgAZBQkFCQVltgIAFRgFGQYCABUZFQWVCAgpJQklBQYABgAGAAg1lgIAGQgVJgIJADhYFSWWBAAZCBUmAgkANgABlZYCABkIFSYCCQA2AAWZCBUoFSWWAgAZCBUmAgkANgAFmQgVKBUllgIAGQgVJgIJADYAOBUoFSYCCQA2EBk4FSYABgAFrxkVBQkFZbYCABUVGDklCAkVBQgFmQgVJZYCABkIFSYCCQA2AAGVlgIAGQgVJgIJADYABZkIFSgVJZYCABkIFSYCCQA2ADgVKBUpBQkFaFMy4yLjB5ldjq \ No newline at end of file diff --git a/integration_test/testdata/identity.aes b/integration_test/testdata/identity.aes new file mode 100644 index 00000000..38ae3f22 --- /dev/null +++ b/integration_test/testdata/identity.aes @@ -0,0 +1,2 @@ +contract Identity = + entrypoint main(z : int) = z \ No newline at end of file diff --git a/integration_test/testdata/identity_bytecode.txt b/integration_test/testdata/identity_bytecode.txt new file mode 100644 index 00000000..1e106a74 --- /dev/null +++ b/integration_test/testdata/identity_bytecode.txt @@ -0,0 +1 @@ +cb_+QP1RgKgrAqzy8P9OGgz6wFSvRD4mtGDnvst1Wq0RUDBbMQm9w/5Avv5ASqgaPJnYzj/UIg5q6R3Se/6i+h+8oTyB/s9mZhwHNU4h8WEbWFpbrjAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKD//////////////////////////////////////////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAuEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA+QHLoLnJVvKLMUmp9Zh6pQXz2hsiCcxXOSNABiu2wb2fn5nqhGluaXS4YAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP//////////////////////////////////////////7kBQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEA//////////////////////////////////////////8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA///////////////////////////////////////////uMxiAABkYgAAhJGAgIBRf7nJVvKLMUmp9Zh6pQXz2hsiCcxXOSNABiu2wb2fn5nqFGIAAMBXUIBRf2jyZ2M4/1CIOaukd0nv+ovofvKE8gf7PZmYcBzVOIfFFGIAAK9XUGABGVEAW2AAGVlgIAGQgVJgIJADYAOBUpBZYABRWVJgAFJgAPNbYACAUmAA81tZWWAgAZCBUmAgkANgABlZYCABkIFSYCCQA2ADgVKBUpBWW2AgAVFRWVCAkVBQgJBQkFZbUFCCkVBQYgAAjFaFMy4yLjAR0UPb \ No newline at end of file diff --git a/integration_test/testdata/identity_initcalldata.txt b/integration_test/testdata/identity_initcalldata.txt new file mode 100644 index 00000000..4b71289f --- /dev/null +++ b/integration_test/testdata/identity_initcalldata.txt @@ -0,0 +1 @@ +cb_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACC5yVbyizFJqfWYeqUF89obIgnMVzkjQAYrtsG9n5+Z6gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAnHQYrA== \ No newline at end of file diff --git a/integration_test/testdata/identity_main42.txt b/integration_test/testdata/identity_main42.txt new file mode 100644 index 00000000..cb83e640 --- /dev/null +++ b/integration_test/testdata/identity_main42.txt @@ -0,0 +1 @@ +cb_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACBo8mdjOP9QiDmrpHdJ7/qL6H7yhPIH+z2ZmHAc1TiHxQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACo7dbVl \ No newline at end of file diff --git a/integration_test/testdata/simplestorage.aes b/integration_test/testdata/simplestorage.aes new file mode 100644 index 00000000..21ae6988 --- /dev/null +++ b/integration_test/testdata/simplestorage.aes @@ -0,0 +1,5 @@ +contract SimpleStorage = + record state = { data : int } + entrypoint init(value : int) : state = { data = value } + function get() : int = state.data + stateful function set(value : int) = put(state{data = value}) diff --git a/integration_test/testdata/simplestorage_bytecode.txt b/integration_test/testdata/simplestorage_bytecode.txt new file mode 100644 index 00000000..cac73566 --- /dev/null +++ b/integration_test/testdata/simplestorage_bytecode.txt @@ -0,0 +1 @@ +cb_+QOERgOgcPPaLbPhA5ZUYYI1viyMLIiudfF0RqUBtpvYh9wt5RL5Ao/5Aoyg4iMdbN/JORbeTLOphXv2XPQPwlb0oUmLP358mAwZk0SEaW5pdAC4wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACg//////////////////////////////////////////8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALkBoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEA//////////////////////////////////////////8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYD//////////////////////////////////////////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAuMJiAAA5YgAAbJGAgFF/4iMdbN/JORbeTLOphXv2XPQPwlb0oUmLP358mAwZk0QUYgAAsFdQYAEZUQBbYAAZWWAgAZCBUmAgkANgAFmQgVKBUllgIAGQgVJgIJADYAOBUpBZYABRWVJgAFJgAPNbYACAUmAA81uAWZCBUllgIAGQgVJgIJADYAAZWWAgAZCBUmAgkANgAFmQgVKBUllgIAGQgVJgIJADYAOBUoFSkFCQVltgIAFRUYOSUICRUFBiAAB0Vok0LjAuMC1yYzEAsRFc7A== \ No newline at end of file diff --git a/integration_test/testdata/simplestorage_init42.txt b/integration_test/testdata/simplestorage_init42.txt new file mode 100644 index 00000000..b1c8385c --- /dev/null +++ b/integration_test/testdata/simplestorage_init42.txt @@ -0,0 +1 @@ +cb_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACDiIx1s38k5Ft5Ms6mFe/Zc9A/CVvShSYs/fnyYDBmTRAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACo7j+li \ No newline at end of file diff --git a/integration_test/testdata/simplestorage_set123.txt b/integration_test/testdata/simplestorage_set123.txt new file mode 100644 index 00000000..b193860a --- /dev/null +++ b/integration_test/testdata/simplestorage_set123.txt @@ -0,0 +1 @@ +cb_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACA6hZQte0c6B/XQTuHZwWpc6rFreRzqkolhGkTD+eW6BwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHv2GVZ7 \ No newline at end of file