Skip to content

Commit

Permalink
Adapting tests to properly encode call data
Browse files Browse the repository at this point in the history
  • Loading branch information
ACassimiro committed Oct 23, 2024
1 parent ffbb0cf commit 6d075ef
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 128 deletions.
135 changes: 60 additions & 75 deletions tests/ukm-with-contract/erc_20_token.1.run
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ list_mock SetAccountStorageHook ( 7162266444908917614 , 300 ) ukmNoResult();
list_mock GetAccountStorageHook ( 7162266444907899391 ) ukmIntResult(9700, u256);
list_mock GetAccountStorageHook ( 7162266444908917614 ) ukmIntResult(300, u256);

call :: bytes_hooks :: empty;
return_value_to_arg;
push "#init(Uint256)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push "#init";
hold_string_from_test_stack;
push "uint256";
hold_list_values_from_test_stack;
push 10000_u256;
call :: bytes_hooks :: append_u256;
hold_list_values_from_test_stack;
mock EncodeCallData;


return_value;
mock CallData;

Expand All @@ -49,14 +51,13 @@ check_eq 0_u32;




call :: bytes_hooks :: empty;
return_value_to_arg;
push "balanceOf(Uint160)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push "balanceOf";
hold_string_from_test_stack;
push "uint160";
hold_list_values_from_test_stack;
push 1010101_u160;
call :: bytes_hooks :: append_u160;
hold_list_values_from_test_stack;
mock EncodeCallData;
return_value;
mock CallData;

Expand All @@ -74,17 +75,15 @@ return_value;
check_eq 10000_u256;



call :: bytes_hooks :: empty;
return_value_to_arg;
push "transfer(Uint160,Uint256)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push "transfer";
hold_string_from_test_stack;
push "uint160";
push "uint256";
hold_list_values_from_test_stack;
push 2020202_u160;
call :: bytes_hooks :: append_u160;
return_value_to_arg;
push 100_u256;
call :: bytes_hooks :: append_u256;
hold_list_values_from_test_stack;
mock EncodeCallData;
return_value;
mock CallData;

Expand All @@ -105,14 +104,13 @@ return_value;
check_eq 1_u64;



call :: bytes_hooks :: empty;
return_value_to_arg;
push "balanceOf(Uint160)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push "balanceOf";
hold_string_from_test_stack;
push "uint160";
hold_list_values_from_test_stack;
push 1010101_u160;
call :: bytes_hooks :: append_u160;
hold_list_values_from_test_stack;
mock EncodeCallData;
return_value;
mock CallData;

Expand All @@ -130,15 +128,13 @@ return_value;
check_eq 9900_u256;




call :: bytes_hooks :: empty;
return_value_to_arg;
push "balanceOf(Uint160)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push "balanceOf";
hold_string_from_test_stack;
push "uint160";
hold_list_values_from_test_stack;
push 2020202_u160;
call :: bytes_hooks :: append_u160;
hold_list_values_from_test_stack;
mock EncodeCallData;
return_value;
mock CallData;

Expand All @@ -156,20 +152,15 @@ return_value;
check_eq 100_u256;






call :: bytes_hooks :: empty;
return_value_to_arg;
push "approve(Uint160,Uint256)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push "approve";
hold_string_from_test_stack;
push "uint160";
push "uint256";
hold_list_values_from_test_stack;
push 3030303_u160;
call :: bytes_hooks :: append_u160;
return_value_to_arg;
push 200_u256;
call :: bytes_hooks :: append_u256;
hold_list_values_from_test_stack;
mock EncodeCallData;
return_value;
mock CallData;

Expand All @@ -190,20 +181,17 @@ return_value;
check_eq 1_u64;



call :: bytes_hooks :: empty;
return_value_to_arg;
push "transferFrom(Uint160,Uint160,Uint256)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push "transferFrom";
hold_string_from_test_stack;
push "uint160";
push "uint160";
push "uint256";
hold_list_values_from_test_stack;
push 1010101_u160;
call :: bytes_hooks :: append_u160;
return_value_to_arg;
push 2020202_u160;
call :: bytes_hooks :: append_u160;
return_value_to_arg;
push 200_u256;
call :: bytes_hooks :: append_u256;
hold_list_values_from_test_stack;
mock EncodeCallData;
return_value;
mock CallData;

Expand All @@ -225,15 +213,13 @@ check_eq 1_u64;





call :: bytes_hooks :: empty;
return_value_to_arg;
push "balanceOf(Uint160)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push "balanceOf";
hold_string_from_test_stack;
push "uint160";
hold_list_values_from_test_stack;
push 1010101_u160;
call :: bytes_hooks :: append_u160;
hold_list_values_from_test_stack;
mock EncodeCallData;
return_value;
mock CallData;

Expand All @@ -252,14 +238,13 @@ check_eq 9700_u256;




call :: bytes_hooks :: empty;
return_value_to_arg;
push "balanceOf(Uint160)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push "balanceOf";
hold_string_from_test_stack;
push "uint160";
hold_list_values_from_test_stack;
push 2020202_u160;
call :: bytes_hooks :: append_u160;
hold_list_values_from_test_stack;
mock EncodeCallData;
return_value;
mock CallData;

Expand Down
19 changes: 9 additions & 10 deletions tests/ukm-with-contract/events.1.run
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
call :: bytes_hooks :: empty;
return_value_to_arg;
push "logEvent(Uint64,Uint64)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push "logEvent";
hold_string_from_test_stack;
push "uint64";
push "uint64";
hold_list_values_from_test_stack;
push 123_u64;
call :: bytes_hooks :: append_u64;
return_value_to_arg;
push 555_u64;
call :: bytes_hooks :: append_u64;
return_value;
push 555_u64;
hold_list_values_from_test_stack;
mock EncodeCallData;
return_value;
mock CallData;

call_contract 12345;
Expand Down
12 changes: 6 additions & 6 deletions tests/ukm-with-contract/require.false.run
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
call :: bytes_hooks :: empty;
return_value_to_arg;
push "myEndpoint(Uint64)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push "myEndpoint";
hold_string_from_test_stack;
push "uint64";
hold_list_values_from_test_stack;
push 0_u64;
call :: bytes_hooks :: append_u64;
hold_list_values_from_test_stack;
mock EncodeCallData;
return_value;
mock CallData;

Expand Down
12 changes: 6 additions & 6 deletions tests/ukm-with-contract/require.true.run
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
call :: bytes_hooks :: empty;
return_value_to_arg;
push "myEndpoint(Uint64)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push "myEndpoint";
hold_string_from_test_stack;
push "uint64";
hold_list_values_from_test_stack;
push 123_u64;
call :: bytes_hooks :: append_u64;
hold_list_values_from_test_stack;
mock EncodeCallData;
return_value;
mock CallData;

Expand Down
27 changes: 13 additions & 14 deletions tests/ukm-with-contract/storage.key.run
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
mock SetAccountStorageHook ( 7010817630605304703 , 123 ) ukmNoResult();
mock GetAccountStorageHook ( 7010817630605304703 ) ukmIntResult(123, u64);

call :: bytes_hooks :: empty;
return_value_to_arg;
push "setMyDataKey(Uint64,Uint64)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push "setMyDataKey";
hold_string_from_test_stack;
push "uint64";
push "uint64";
hold_list_values_from_test_stack;
push 555_u64;
call :: bytes_hooks :: append_u64;
return_value_to_arg;
push 123_u64;
call :: bytes_hooks :: append_u64;
hold_list_values_from_test_stack;
mock EncodeCallData;
return_value;
mock CallData;

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


call :: bytes_hooks :: empty;
return_value_to_arg;
push "getMyDataKey(Uint64)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push "getMyDataKey";
hold_string_from_test_stack;
push "uint64";
hold_list_values_from_test_stack;
push 555_u64;
call :: bytes_hooks :: append_u64;
hold_list_values_from_test_stack;
mock EncodeCallData;
return_value;
mock CallData;

Expand Down
19 changes: 9 additions & 10 deletions tests/ukm-with-contract/storage.simple.run
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
mock SetAccountStorageHook ( 1809217465971809 , 123 ) ukmNoResult();
mock GetAccountStorageHook ( 1809217465971809 ) ukmIntResult(123, u64);

call :: bytes_hooks :: empty;
return_value_to_arg;
push "setMyData(Uint64)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push "setMyData";
hold_string_from_test_stack;
push "uint64";
hold_list_values_from_test_stack;
push 123_u64;
call :: bytes_hooks :: append_u64;
hold_list_values_from_test_stack;
mock EncodeCallData;
return_value;
mock CallData;

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


call :: bytes_hooks :: empty;
return_value_to_arg;
push "getMyData()";
call :: bytes_hooks :: append_str;
push "getMyData";
hold_string_from_test_stack;
mock EncodeCallData;
return_value;
mock CallData;

Expand Down
13 changes: 6 additions & 7 deletions ukm-semantics/main/encoding/encoder.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ module UKM-CALLDATA-ENCODER
// Function signature encoding
rule encodeFunctionSignature(FuncName:String, RL:List, "") =>
encodeFunctionSignature("", RL:List, FuncName +String "(")
encodeFunctionSignature("", RL:List, FuncName +String "(") [priority(40)]
rule encodeFunctionSignature("", ListItem(FuncParam:String) RL:List, FS) =>
encodeFunctionSignature("", RL, FS +String FuncParam +String ",") [owise]
// The last param does not have a follow up comma
rule encodeFunctionSignature("", ListItem(FuncParam:String) .List, FS) =>
encodeFunctionSignature("", .List, FS +String FuncParam +String ")" )
encodeFunctionSignature("", .List, FS +String FuncParam )
rule encodeFunctionSignature("", .List, FS) => String2Bytes(substrString(Keccak256(String2Bytes(FS)), 0, 8))
rule encodeFunctionSignature("", .List, FS) => String2Bytes(substrString(Keccak256(String2Bytes(FS +String ")")), 0, 8))
rule encodeFunctionSignatureAsString(FS) => substrString(Keccak256(String2Bytes(FS)), 0, 8)
rule encodeFunctionSignature(FS:String:StringOrError) => String2Bytes(substrString(Keccak256(String2Bytes(FS)), 0, 8))
Expand All @@ -68,10 +68,9 @@ module UKM-CALLDATA-ENCODER
rule convertToKBytes(u128(V), "uint128") => Int2Bytes(32, MInt2Unsigned(V), BE:Endianness)
rule convertToKBytes(true, "bool") => Int2Bytes(32, 1, BE:Endianness)
rule convertToKBytes(false, "bool") => Int2Bytes(32, 0, BE:Endianness)
// TODO: as we currently do not support u160 (addresses) or u256, we're converting them to u64 for now
rule convertToKBytes(u64(V), "uint256") => Int2Bytes(32, MInt2Unsigned(V), BE:Endianness)
rule convertToKBytes(u64(V), "uint160") => Int2Bytes(32, MInt2Unsigned(V), BE:Endianness)
rule convertToKBytes(u64(V), "address") => Int2Bytes(32, MInt2Unsigned(V), BE:Endianness)
rule convertToKBytes(u256(V), "uint256") => Int2Bytes(32, MInt2Unsigned(V), BE:Endianness)
rule convertToKBytes(u160(V), "uint160") => Int2Bytes(32, MInt2Unsigned(V), BE:Endianness)
rule convertToKBytes(u160(V), "address") => Int2Bytes(32, MInt2Unsigned(V), BE:Endianness)
endmodule
Expand Down
Loading

0 comments on commit 6d075ef

Please sign in to comment.