Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More clear tests #187

Merged
merged 12 commits into from
Nov 28, 2024
10 changes: 8 additions & 2 deletions compilation/prepare-rust-bundle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ cat $ULM_CONTRACTS_TESTING_INPUT_DIR/bytes_hooks.rs >> $output_file
echo ">)>" >> $output_file

echo "<(<" >> $output_file
echo "::test_helpers" >> $output_file
echo "::debug" >> $output_file
echo "<|>" >> $output_file
cat $ULM_CONTRACTS_TESTING_INPUT_DIR/test_helpers.rs >> $output_file
cat $ULM_CONTRACTS_TESTING_INPUT_DIR/debug.rs >> $output_file
echo ">)>" >> $output_file

echo "<(<" >> $output_file
Expand All @@ -48,6 +48,12 @@ echo "<|>" >> $output_file
cat $ULM_CONTRACTS_TESTING_INPUT_DIR/single_value_mapper.rs >> $output_file
echo ">)>" >> $output_file

echo "<(<" >> $output_file
echo "::test_helpers" >> $output_file
echo "<|>" >> $output_file
cat $ULM_CONTRACTS_TESTING_INPUT_DIR/test_helpers.rs >> $output_file
echo ">)>" >> $output_file

echo "<(<" >> $output_file
echo "::ulm" >> $output_file
echo "<|>" >> $output_file
Expand Down
12 changes: 12 additions & 0 deletions tests/ulm-contracts/debug.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
extern "C" {
fn debug_u256(value: u256);
fn debug_u160(value: u160);
fn debug_u128(value: u128);
fn debug_u64(value: u64);
fn debug_u32(value: u32);
fn debug_u16(value: u16);
fn debug_u8(value: u8);
fn debug_bool(value: bool);
fn debug_str(value: &str);
fn debug_unit(value: ());
}
8 changes: 1 addition & 7 deletions tests/ulm-with-contract/endpoints.1.run
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
push "myEndpoint";
hold_string_from_test_stack;
push "uint64";
hold_list_values_from_test_stack;
push 123_u64;
hold_list_values_from_test_stack;
encode_call_data;
encode_call_data myEndpoint(123_u64:u64);

return_value;
mock CallData;
Expand Down
10 changes: 2 additions & 8 deletions tests/ulm-with-contract/endpoints.2.run
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
push "myEndpoint";
hold_string_from_test_stack;
push "uint64";
hold_list_values_from_test_stack;
push 1_u64;
hold_list_values_from_test_stack;
encode_call_data_to_string;
encode_call_data myEndpoint(1_u64:u64);
return_value;
check_eq "\x81\x92(T\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01"
check_eq_bytes b"\x81\x92(T\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01"
8 changes: 1 addition & 7 deletions tests/ulm-with-contract/endpoints.notfound.run
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
push "noEndpoint";
hold_string_from_test_stack;
push "uint64";
hold_list_values_from_test_stack;
push 123_u64;
hold_list_values_from_test_stack;
encode_call_data;
encode_call_data noEndpoint(123_u64:u64);

return_value;
mock CallData;
Expand Down
132 changes: 35 additions & 97 deletions tests/ulm-with-contract/erc_20_token.1.run
Original file line number Diff line number Diff line change
@@ -1,36 +1,30 @@
list_mock GetAccountStorageHook ( 13032332009337290780939164280742955473285243463246449969298152790977293574652 ) ulmIntResult(0, u256);
list_mock SetAccountStorageHook ( 13032332009337290780939164280742955473285243463246449969298152790977293574652 , 10000 ) ulmNoResult();
list_mock GetAccountStorageHook ( 61159765391625381932700807532824927387505868579121206115135228514320059425645 ) ulmIntResult(0, u256);
list_mock SetAccountStorageHook ( 61159765391625381932700807532824927387505868579121206115135228514320059425645 , 10000 ) ulmNoResult();
list_mock GetAccountStorageHook ( 61159765391625381932700807532824927387505868579121206115135228514320059425645 ) ulmIntResult(10000, u256);
list_mock GetAccountStorageHook ( 61159765391625381932700807532824927387505868579121206115135228514320059425645 ) ulmIntResult(10000, u256);
list_mock GetAccountStorageHook ( 61159765391625381932700807532824927387505868579121206115135228514320059425645 ) ulmIntResult(10000, u256);
list_mock SetAccountStorageHook ( 61159765391625381932700807532824927387505868579121206115135228514320059425645 , 9900 ) ulmNoResult();
list_mock GetAccountStorageHook ( 107935355587284645605585039702009686485686559005730386557515578263121021727641 ) ulmIntResult(0, u256);
list_mock SetAccountStorageHook ( 107935355587284645605585039702009686485686559005730386557515578263121021727641 , 100 ) ulmNoResult();
list_mock Log3Hook ( 100389287136786176327247604509743168900146139575972864366142685224231313322991 , 1010101 , 2020202 , b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00d" ) ulmNoResult();
list_mock GetAccountStorageHook ( 61159765391625381932700807532824927387505868579121206115135228514320059425645 ) ulmIntResult(9900, u256);
list_mock GetAccountStorageHook ( 107935355587284645605585039702009686485686559005730386557515578263121021727641 ) ulmIntResult(100, u256);
list_mock SetAccountStorageHook ( 6299478510657022222390882510197411465571447485061513230872540120223652878023 , 200 ) ulmNoResult();
list_mock Log3Hook ( 63486140976153616755203102783360879283472101686154884697241723088393386309925 , 1010101 , 3030303 , b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc8" ) ulmNoResult();
list_mock GetAccountStorageHook ( 6299478510657022222390882510197411465571447485061513230872540120223652878023 ) ulmIntResult(200, u256);
list_mock SetAccountStorageHook ( 6299478510657022222390882510197411465571447485061513230872540120223652878023 , 0 ) ulmNoResult();
list_mock GetAccountStorageHook ( 61159765391625381932700807532824927387505868579121206115135228514320059425645 ) ulmIntResult(9900, u256);
list_mock GetAccountStorageHook ( 61159765391625381932700807532824927387505868579121206115135228514320059425645 ) ulmIntResult(9900, u256);
list_mock SetAccountStorageHook ( 61159765391625381932700807532824927387505868579121206115135228514320059425645 , 9700 ) ulmNoResult();
list_mock GetAccountStorageHook ( 107935355587284645605585039702009686485686559005730386557515578263121021727641 ) ulmIntResult(100, u256);
list_mock SetAccountStorageHook ( 107935355587284645605585039702009686485686559005730386557515578263121021727641 , 300 ) ulmNoResult();
list_mock Log3Hook ( 100389287136786176327247604509743168900146139575972864366142685224231313322991 , 1010101 , 2020202 , b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc8" ) ulmNoResult();
list_mock GetAccountStorageHook ( 61159765391625381932700807532824927387505868579121206115135228514320059425645 ) ulmIntResult(9700, u256);
list_mock GetAccountStorageHook ( 107935355587284645605585039702009686485686559005730386557515578263121021727641 ) ulmIntResult(300, u256);

push "uint256";
hold_list_values_from_test_stack;
push 10000_u256;
hold_list_values_from_test_stack;
encode_constructor_data;


list_mock GetAccountStorageHook ( storageKey("total_supply", ) ) ulmIntResult(0, u256);
list_mock SetAccountStorageHook ( storageKey("total_supply", ) , 10000_u256 ) ulmNoResult();
list_mock GetAccountStorageHook ( storageKey("balances", 1010101_u160:u160) ) ulmIntResult(0, u256);
list_mock SetAccountStorageHook ( storageKey("balances", 1010101_u160:u160) , 10000_u256 ) ulmNoResult();
list_mock GetAccountStorageHook ( storageKey("balances", 1010101_u160:u160) ) ulmIntResult(10000, u256);
list_mock GetAccountStorageHook ( storageKey("balances", 1010101_u160:u160) ) ulmIntResult(10000, u256);
list_mock GetAccountStorageHook ( storageKey("balances", 1010101_u160:u160) ) ulmIntResult(10000, u256);
list_mock SetAccountStorageHook ( storageKey("balances", 1010101_u160:u160) , 9900_u256 ) ulmNoResult();
list_mock GetAccountStorageHook ( storageKey("balances", 2020202_u160:u160) ) ulmIntResult(0, u256);
list_mock SetAccountStorageHook ( storageKey("balances", 2020202_u160:u160) , 100_u256 ) ulmNoResult();
list_mock Log3Hook ( eventSignature("Transfer(address,address,uint256)") , 1010101 , 2020202 , encodeValues(100_u256:u256) ) ulmNoResult();
list_mock GetAccountStorageHook ( storageKey("balances", 1010101_u160:u160) ) ulmIntResult(9900, u256);
list_mock GetAccountStorageHook ( storageKey("balances", 2020202_u160:u160) ) ulmIntResult(100, u256);
list_mock SetAccountStorageHook ( storageKey("allowances", 1010101_u160:u160, 3030303_u160:u160) , 200_u256 ) ulmNoResult();
list_mock Log3Hook ( eventSignature("Approval(address,address,uint256)") , 1010101 , 3030303 , encodeValues(200_u256:u256) ) ulmNoResult();
list_mock GetAccountStorageHook ( storageKey("allowances", 1010101_u160:u160, 3030303_u160:u160) ) ulmIntResult(200, u256);
list_mock SetAccountStorageHook ( storageKey("allowances", 1010101_u160:u160, 3030303_u160:u160) , 0_u256 ) ulmNoResult();
list_mock GetAccountStorageHook ( storageKey("balances", 1010101_u160:u160) ) ulmIntResult(9900, u256);
list_mock GetAccountStorageHook ( storageKey("balances", 1010101_u160:u160) ) ulmIntResult(9900, u256);
list_mock SetAccountStorageHook ( storageKey("balances", 1010101_u160:u160) , 9700_u256 ) ulmNoResult();
list_mock GetAccountStorageHook ( storageKey("balances", 2020202_u160:u160) ) ulmIntResult(100, u256);
list_mock SetAccountStorageHook ( storageKey("balances", 2020202_u160:u160) , 300_u256 ) ulmNoResult();
list_mock Log3Hook ( eventSignature("Transfer(address,address,uint256)") , 1010101 , 2020202 , encodeValues(200_u256:u256) ) ulmNoResult();
list_mock GetAccountStorageHook ( storageKey("balances", 1010101_u160:u160) ) ulmIntResult(9700, u256);
list_mock GetAccountStorageHook ( storageKey("balances", 2020202_u160:u160) ) ulmIntResult(300, u256);

encode_constructor_data 10000_u256:u256;
return_value;
mock CallData;

Expand All @@ -51,13 +45,7 @@ check_eq 0_u32;



push "balanceOf";
hold_string_from_test_stack;
push "address";
hold_list_values_from_test_stack;
push 1010101_u160;
hold_list_values_from_test_stack;
encode_call_data;
encode_call_data balanceOf(1010101_u160:u160);
return_value;
mock CallData;

Expand All @@ -75,15 +63,7 @@ return_value;
check_eq 10000_u256;


push "transfer";
hold_string_from_test_stack;
push "address";
push "uint256";
hold_list_values_from_test_stack;
push 2020202_u160;
push 100_u256;
hold_list_values_from_test_stack;
encode_call_data;
encode_call_data transfer(2020202_u160:u160, 100_u256:u256);
return_value;
mock CallData;

Expand All @@ -104,13 +84,7 @@ return_value;
check_eq 1_u64;


push "balanceOf";
hold_string_from_test_stack;
push "address";
hold_list_values_from_test_stack;
push 1010101_u160;
hold_list_values_from_test_stack;
encode_call_data;
encode_call_data balanceOf(1010101_u160:u160);
return_value;
mock CallData;

Expand All @@ -128,13 +102,7 @@ return_value;
check_eq 9900_u256;


push "balanceOf";
hold_string_from_test_stack;
push "address";
hold_list_values_from_test_stack;
push 2020202_u160;
hold_list_values_from_test_stack;
encode_call_data;
encode_call_data balanceOf(2020202_u160:u160);
return_value;
mock CallData;

Expand All @@ -152,15 +120,7 @@ return_value;
check_eq 100_u256;


push "approve";
hold_string_from_test_stack;
push "address";
push "uint256";
hold_list_values_from_test_stack;
push 3030303_u160;
push 200_u256;
hold_list_values_from_test_stack;
encode_call_data;
encode_call_data approve(3030303_u160:u160, 200_u256:u256);
return_value;
mock CallData;

Expand All @@ -181,17 +141,7 @@ return_value;
check_eq 1_u64;


push "transferFrom";
hold_string_from_test_stack;
push "address";
push "address";
push "uint256";
hold_list_values_from_test_stack;
push 1010101_u160;
push 2020202_u160;
push 200_u256;
hold_list_values_from_test_stack;
encode_call_data;
encode_call_data transferFrom(1010101_u160:u160, 2020202_u160:u160, 200_u256:u256);
return_value;
mock CallData;

Expand All @@ -213,13 +163,7 @@ check_eq 1_u64;



push "balanceOf";
hold_string_from_test_stack;
push "address";
hold_list_values_from_test_stack;
push 1010101_u160;
hold_list_values_from_test_stack;
encode_call_data;
encode_call_data balanceOf(1010101_u160:u160);
return_value;
mock CallData;

Expand All @@ -238,13 +182,7 @@ check_eq 9700_u256;



push "balanceOf";
hold_string_from_test_stack;
push "address";
hold_list_values_from_test_stack;
push 2020202_u160;
hold_list_values_from_test_stack;
encode_call_data;
encode_call_data balanceOf(2020202_u160:u160);
return_value;
mock CallData;

Expand Down
2 changes: 1 addition & 1 deletion tests/ulm-with-contract/erc_20_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub trait Erc20Token {
fn s_balances(&self, address: u160) -> ::single_value_mapper::SingleValueMapper<u256>;

// #[view(getAllowances)]
#[storage_mapper("balances")]
#[storage_mapper("allowances")]
fn s_allowances(&self, account: u160, spender: u160) -> ::single_value_mapper::SingleValueMapper<u256>;

#[event("Transfer")]
Expand Down
10 changes: 1 addition & 9 deletions tests/ulm-with-contract/events.1.run
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
list_mock Log2Hook ( 74657075023537209477280918141328480329188930599530356189395812678724488965561 , 123 , b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02+" ) ulmNoResult();

push "logEvent";
hold_string_from_test_stack;
push "uint64";
push "uint64";
hold_list_values_from_test_stack;
push 123_u64;
push 555_u64;
hold_list_values_from_test_stack;
encode_call_data;
encode_call_data logEvent(123_u64:u64, 555_u64:u64);
return_value;
mock CallData;

Expand Down
8 changes: 1 addition & 7 deletions tests/ulm-with-contract/require.false.run
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
push "myEndpoint";
hold_string_from_test_stack;
push "uint64";
hold_list_values_from_test_stack;
push 0_u64;
hold_list_values_from_test_stack;
encode_call_data;
encode_call_data myEndpoint(0_u64:u64);
return_value;
mock CallData;

Expand Down
8 changes: 1 addition & 7 deletions tests/ulm-with-contract/require.true.run
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
push "myEndpoint";
hold_string_from_test_stack;
push "uint64";
hold_list_values_from_test_stack;
push 123_u64;
hold_list_values_from_test_stack;
encode_call_data;
encode_call_data myEndpoint(123_u64:u64);
return_value;
mock CallData;

Expand Down
18 changes: 5 additions & 13 deletions tests/ulm-with-contract/storage.256.run
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
mock SetAccountStorageHook ( 81899343944223093934060911023235694134954301913235101281428181165721203435003 , 1000000000000000000000000000000000000000000000000000000000000 ) ulmNoResult();
mock GetAccountStorageHook ( 81899343944223093934060911023235694134954301913235101281428181165721203435003 ) ulmIntResult(1000000000000000000000000000000000000000000000000000000000000, u256);

push "setMyData256";
hold_string_from_test_stack;
push "uint256";
hold_list_values_from_test_stack;
push 1_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_u256;
hold_list_values_from_test_stack;
encode_call_data;
mock SetAccountStorageHook ( storageKey("myData256", ) , 1_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_u256 ) ulmNoResult();
mock GetAccountStorageHook ( storageKey("myData256", ) ) ulmIntResult(1000000000000000000000000000000000000000000000000000000000000, u256);

encode_call_data setMyData256(1_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_u256:u256);
return_value;
mock CallData;

Expand All @@ -19,9 +13,7 @@ push_status;
check_eq 2;


push "getMyData256";
hold_string_from_test_stack;
encode_call_data;
encode_call_data getMyData256();
return_value;
mock CallData;

Expand Down
24 changes: 5 additions & 19 deletions tests/ulm-with-contract/storage.key.run
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
mock SetAccountStorageHook ( 89307555350153532481150451243271458944170707741354029868021544305102042370102 , 123 ) ulmNoResult();
mock GetAccountStorageHook ( 89307555350153532481150451243271458944170707741354029868021544305102042370102 ) ulmIntResult(123, u256);

push "setMyDataKey";
hold_string_from_test_stack;
push "uint64";
push "uint64";
hold_list_values_from_test_stack;
push 555_u64;
push 123_u64;
hold_list_values_from_test_stack;
encode_call_data;
mock SetAccountStorageHook ( storageKey("myDataKey", 555_u64:u64) , 123_u64 ) ulmNoResult();
mock GetAccountStorageHook ( storageKey("myDataKey", 555_u64:u64) ) ulmIntResult(123, u256);

encode_call_data setMyDataKey(555_u64:u64, 123_u64:u64);
return_value;
mock CallData;

Expand All @@ -21,13 +13,7 @@ push_status;
check_eq 2;


push "getMyDataKey";
hold_string_from_test_stack;
push "uint64";
hold_list_values_from_test_stack;
push 555_u64;
hold_list_values_from_test_stack;
encode_call_data;
encode_call_data getMyDataKey(555_u64:u64);
return_value;
mock CallData;

Expand Down
Loading