diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d33869ebf..6415bbb90 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -158,6 +158,11 @@ test:contracts_macros.sh: script: - dune build @src/bin_client/runtest_contracts_macros.sh +test:contracts_mini_scenarios.sh: + <<: *test_definition + script: + - dune build @src/bin_client/runtest_contracts_mini_scenarios.sh + test:multinode.sh: <<: *test_definition script: diff --git a/src/bin_client/test/contracts/create_contract.tz b/src/bin_client/test/contracts_mini_scenarios/create_contract.tz similarity index 100% rename from src/bin_client/test/contracts/create_contract.tz rename to src/bin_client/test/contracts_mini_scenarios/create_contract.tz diff --git a/src/bin_client/test/contracts/default_account.tz b/src/bin_client/test/contracts_mini_scenarios/default_account.tz similarity index 100% rename from src/bin_client/test/contracts/default_account.tz rename to src/bin_client/test/contracts_mini_scenarios/default_account.tz diff --git a/src/bin_client/test/contracts/vote_for_delegate.tz b/src/bin_client/test/contracts_mini_scenarios/vote_for_delegate.tz similarity index 100% rename from src/bin_client/test/contracts/vote_for_delegate.tz rename to src/bin_client/test/contracts_mini_scenarios/vote_for_delegate.tz diff --git a/src/bin_client/test/dune b/src/bin_client/test/dune index 2cee2772a..0414882d2 100644 --- a/src/bin_client/test/dune +++ b/src/bin_client/test/dune @@ -61,6 +61,21 @@ %{bin:tezos-client} %{bin:tezos-admin-client}))) +(alias + (name runtest_contracts_mini_scenarios.sh) + (deps sandbox.json + test_lib.inc.sh + (glob_files contracts_mini_scenarios/*)) + (locks /tcp-port/18731 + /tcp-port/19731) + (action + (run bash %{dep:test_contracts_mini_scenarios.sh} + %{bin:tezos-sandboxed-node.sh} + %{bin:tezos-node} + %{bin:tezos-init-sandboxed-client.sh} + %{bin:tezos-client} + %{bin:tezos-admin-client}))) + (alias (name runtest_multinode.sh) (deps sandbox.json @@ -131,6 +146,7 @@ (alias runtest_contracts.sh) (alias runtest_contracts_opcode.sh) (alias runtest_contracts_macros.sh) + (alias runtest_contracts_mini_scenarios.sh) (alias runtest_multinode.sh) (alias runtest_injection.sh) (alias runtest_tls.sh) diff --git a/src/bin_client/test/test_contracts.sh b/src/bin_client/test/test_contracts.sh index 05916c81c..059dad3e7 100755 --- a/src/bin_client/test/test_contracts.sh +++ b/src/bin_client/test/test_contracts.sh @@ -427,26 +427,26 @@ assert_fails $client transfer 0 from bootstrap1 to replay #assert_balance create_account "1000 ꜩ" # Creates a contract, transfers data to it and stores the data -init_with_transfer $contract_dir/create_contract.tz $key2 Unit 1,000 bootstrap1 -assert_balance create_contract "1000 ꜩ" -created_contract=\ -`$client transfer 0 from bootstrap1 to create_contract -arg '(Left "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx")' \ -| grep 'New contract' \ -| sed -E 's/.*(KT1[a-zA-Z0-9]+).*/\1/' \ -| head -1` -bake -assert_storage_contains $created_contract '"abcdefg"' -assert_balance $created_contract "100 ꜩ" -assert_balance create_contract "900 ꜩ" +#init_with_transfer $contract_dir/create_contract.tz $key2 Unit 1,000 bootstrap1 +#assert_balance create_contract "1000 ꜩ" +#created_contract=\ +#`$client transfer 0 from bootstrap1 to create_contract -arg '(Left "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx")' \ +#| grep 'New contract' \ +#| sed -E 's/.*(KT1[a-zA-Z0-9]+).*/\1/' \ +#| head -1` +#bake +#assert_storage_contains $created_contract '"abcdefg"' +#assert_balance $created_contract "100 ꜩ" +#assert_balance create_contract "900 ꜩ" # Test IMPLICIT_ACCOUNT -init_with_transfer $contract_dir/default_account.tz $key1 \ - Unit 1,000 bootstrap1 -bake_after $client transfer 0 from bootstrap1 to default_account -arg "\"$BOOTSTRAP4_IDENTITY\"" -assert_balance $BOOTSTRAP4_IDENTITY "4000100 ꜩ" -account=tz1SuakBpFdG9b4twyfrSMqZzruxhpMeSrE5 -bake_after $client transfer 0 from bootstrap1 to default_account -arg "\"$account\"" -assert_balance $account "100 ꜩ" +#init_with_transfer $contract_dir/default_account.tz $key1 \ +# Unit 1,000 bootstrap1 +#bake_after $client transfer 0 from bootstrap1 to default_account -arg "\"$BOOTSTRAP4_IDENTITY\"" +#assert_balance $BOOTSTRAP4_IDENTITY "4000100 ꜩ" +#account=tz1SuakBpFdG9b4twyfrSMqZzruxhpMeSrE5 +#bake_after $client transfer 0 from bootstrap1 to default_account -arg "\"$account\"" +#assert_balance $account "100 ꜩ" # Test SELF init_with_transfer $contract_dir/self.tz $key1 \ @@ -504,24 +504,24 @@ bake_after $client transfer 0 from bootstrap1 to split_bytes -arg '0xddeeff' assert_storage_contains split_bytes '{ 0xaa ; 0xbb ; 0xcc ; 0xdd ; 0xee ; 0xff }' # Test SET_DELEGATE -b2='tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN' -b3='tz1faswCTDciRzE4oJ9jn2Vm2dvjeyA9fUzU' -b4='tz1b7tUupMgCNw2cCLpKTkSD1NZzB5TkP2sv' -b5='tz1ddb9NMYHZi5UzPdzTZMYQQZoMub195zgv' -init_with_transfer $contract_dir/vote_for_delegate.tz bootstrap1 \ - "(Pair (Pair \"$b3\" None) (Pair \"$b4\" None))" 1,000 bootstrap1 -$client get delegate for vote_for_delegate | assert_in_output none +#b2='tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN' +#b3='tz1faswCTDciRzE4oJ9jn2Vm2dvjeyA9fUzU' +#b4='tz1b7tUupMgCNw2cCLpKTkSD1NZzB5TkP2sv' +#b5='tz1ddb9NMYHZi5UzPdzTZMYQQZoMub195zgv' +#init_with_transfer $contract_dir/vote_for_delegate.tz bootstrap1 \ +# "(Pair (Pair \"$b3\" None) (Pair \"$b4\" None))" 1,000 bootstrap1 +#$client get delegate for vote_for_delegate | assert_in_output none -assert_fails $client transfer 0 from bootstrap1 to vote_for_delegate -arg None -assert_fails $client transfer 0 from bootstrap2 to vote_for_delegate -arg None -bake_after $client transfer 0 from bootstrap3 to vote_for_delegate -arg "(Some \"$b5\")" -assert_storage_contains vote_for_delegate "\"$b5\"" -$client get delegate for vote_for_delegate | assert_in_output none -bake_after $client transfer 0 from bootstrap4 to vote_for_delegate -arg "(Some \"$b2\")" -assert_storage_contains vote_for_delegate "\"$b2\"" -$client get delegate for vote_for_delegate | assert_in_output none -bake_after $client transfer 0 from bootstrap4 to vote_for_delegate -arg "(Some \"$b5\")" -$client get delegate for vote_for_delegate | assert_in_output "$b5" +#assert_fails $client transfer 0 from bootstrap1 to vote_for_delegate -arg None +#assert_fails $client transfer 0 from bootstrap2 to vote_for_delegate -arg None +#bake_after $client transfer 0 from bootstrap3 to vote_for_delegate -arg "(Some \"$b5\")" +#assert_storage_contains vote_for_delegate "\"$b5\"" +#$client get delegate for vote_for_delegate | assert_in_output none +#bake_after $client transfer 0 from bootstrap4 to vote_for_delegate -arg "(Some \"$b2\")" +#assert_storage_contains vote_for_delegate "\"$b2\"" +#$client get delegate for vote_for_delegate | assert_in_output none +#bake_after $client transfer 0 from bootstrap4 to vote_for_delegate -arg "(Some \"$b5\")" +#$client get delegate for vote_for_delegate | assert_in_output "$b5" # Test sets and map literals assert_fails $client typecheck data '{ Elt 0 1 ; Elt 0 1 }' against type '(map nat nat)' diff --git a/src/bin_client/test/test_contracts_mini_scenarios.sh b/src/bin_client/test/test_contracts_mini_scenarios.sh new file mode 100644 index 000000000..0061aa4e8 --- /dev/null +++ b/src/bin_client/test/test_contracts_mini_scenarios.sh @@ -0,0 +1,73 @@ +#!/bin/bash + +set -e +set -o pipefail + +test_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)")" +source $test_dir/test_lib.inc.sh "$@" + +start_node 1 +activate_alpha + +$client -w none config update + +bake + +key1=foo +key2=bar + +$client gen keys $key1 +$client gen keys $key2 + +printf "\n\n" + +# Assert all contracts typecheck +if [ ! $NO_TYPECHECK ] ; then + for contract in `ls $contract_scenarios_dir/*.tz`; do + printf "[Typechecking %s]\n" "$contract"; + ${client} typecheck script "$contract"; + done + printf "All contracts are well typed\n\n" +fi + +# Creates a contract, transfers data to it and stores the data +init_with_transfer $contract_scenarios_dir/create_contract.tz $key2 Unit 1,000 bootstrap1 +assert_balance create_contract "1000 ꜩ" +created_contract=\ +`$client transfer 0 from bootstrap1 to create_contract -arg '(Left "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx")' \ +| grep 'New contract' \ +| sed -E 's/.*(KT1[a-zA-Z0-9]+).*/\1/' \ +| head -1` +bake +assert_storage_contains $created_contract '"abcdefg"' +assert_balance $created_contract "100 ꜩ" +assert_balance create_contract "900 ꜩ" + +# Test IMPLICIT_ACCOUNT +init_with_transfer $contract_scenarios_dir/default_account.tz $key1 \ + Unit 1,000 bootstrap1 +bake_after $client transfer 0 from bootstrap1 to default_account -arg "\"$BOOTSTRAP4_IDENTITY\"" +assert_balance $BOOTSTRAP4_IDENTITY "4000100 ꜩ" +account=tz1SuakBpFdG9b4twyfrSMqZzruxhpMeSrE5 +bake_after $client transfer 0 from bootstrap1 to default_account -arg "\"$account\"" +assert_balance $account "100 ꜩ" + +# Test SET_DELEGATE +b2='tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN' +b3='tz1faswCTDciRzE4oJ9jn2Vm2dvjeyA9fUzU' +b4='tz1b7tUupMgCNw2cCLpKTkSD1NZzB5TkP2sv' +b5='tz1ddb9NMYHZi5UzPdzTZMYQQZoMub195zgv' +init_with_transfer $contract_scenarios_dir/vote_for_delegate.tz bootstrap1 \ + "(Pair (Pair \"$b3\" None) (Pair \"$b4\" None))" 1,000 bootstrap1 +$client get delegate for vote_for_delegate | assert_in_output none + +assert_fails $client transfer 0 from bootstrap1 to vote_for_delegate -arg None +assert_fails $client transfer 0 from bootstrap2 to vote_for_delegate -arg None +bake_after $client transfer 0 from bootstrap3 to vote_for_delegate -arg "(Some \"$b5\")" +assert_storage_contains vote_for_delegate "\"$b5\"" +$client get delegate for vote_for_delegate | assert_in_output none +bake_after $client transfer 0 from bootstrap4 to vote_for_delegate -arg "(Some \"$b2\")" +assert_storage_contains vote_for_delegate "\"$b2\"" +$client get delegate for vote_for_delegate | assert_in_output none +bake_after $client transfer 0 from bootstrap4 to vote_for_delegate -arg "(Some \"$b5\")" +$client get delegate for vote_for_delegate | assert_in_output "$b5" diff --git a/src/bin_client/test/test_lib.inc.sh b/src/bin_client/test/test_lib.inc.sh index b112d2abf..09287e91b 100755 --- a/src/bin_client/test/test_lib.inc.sh +++ b/src/bin_client/test/test_lib.inc.sh @@ -19,6 +19,7 @@ local_compiler="${6:-$test_dir/../../../_build/default/src/lib_protocol_compiler contract_dir="contracts" contract_op_dir="contracts_opcode" contract_macros_dir="contracts_macros" +contract_scenarios_dir="contracts_mini_scenarios" source $tezos_sandboxed_node source $tezos_init_sandboxed_client