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

Use the new int types for erc-20 #165

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/ukm-contracts/address.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn is_zero(address: u64) -> bool {
address == 0_u64
fn is_zero(address: u160) -> bool {
address == 0_u160
}
4 changes: 4 additions & 0 deletions tests/ukm-contracts/bytes_hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ extern "C" {
fn empty() -> u64;
fn length(bytes_id: u64) -> u32;

fn append_u256(bytes_id: u64, value: u256) -> u64;
fn append_u160(bytes_id: u64, value: u160) -> u64;
fn append_u128(bytes_id: u64, value: u128) -> u64;
fn append_u64(bytes_id: u64, value: u64) -> u64;
fn append_u32(bytes_id: u64, value: u32) -> u64;
Expand All @@ -10,6 +12,8 @@ extern "C" {
fn append_bool(bytes_id: u64, value: bool) -> u64;
fn append_str(bytes_id: u64, value: &str) -> u64;

fn decode_u256(bytes_id: u64) -> (u64, u256);
fn decode_u160(bytes_id: u64) -> (u64, u160);
fn decode_u128(bytes_id: u64) -> (u64, u128);
fn decode_u64(bytes_id: u64) -> (u64, u64);
fn decode_u32(bytes_id: u64) -> (u64, u32);
Expand Down
8 changes: 8 additions & 0 deletions tests/ukm-contracts/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ fn decode_single_u64(bytes_id: u64) -> u64 {
};
value
}

fn decode_single_u256(bytes_id: u64) -> u256 {
let (remaining_id, value) = :: bytes_hooks :: decode_u256(bytes_id);
if :: bytes_hooks :: length(remaining_id) > 0_u32 {
fail();
};
value
}
46 changes: 23 additions & 23 deletions tests/ukm-contracts/ukm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pub const EVMC_NONCE_EXCEEDED: u64 = 15_u64;
extern {
// block parameters
fn sample_method(&self) -> u64;
fn GasLimit(&self) -> u64;
fn BaseFee(&self) -> u64;
fn GasLimit(&self) -> u256;
fn BaseFee(&self) -> u256;
fn Coinbase(&self) -> u64;
fn BlockTimestamp(&self) -> u64;
fn BlockNumber(&self) -> u64;
Expand All @@ -37,42 +37,42 @@ extern {
fn Origin(&self) -> u64;

// message parameters
fn Address(&self) -> u64;
fn Caller(&self) -> u64;
fn CallValue(&self) -> u64;
fn Address(&self) -> u160;
fn Caller(&self) -> u160;
fn CallValue(&self) -> u256;
fn CallData(&self) -> Bytes;

// chain parameters
fn ChainId(&self) -> u64;

// account getters
fn GetAccountBalance(&self, acct: u64) -> u64;
fn GetAccountCode(&self, acct: u64) -> u64;
fn GetAccountStorage(&self, key: u64) -> u64;
fn GetAccountOrigStorage(&self, key: u64) -> u64;
fn GetAccountTransientStorage(&self, key: u64) -> u64;
fn IsAccountEmpty(&self, acct: u64) -> bool;
fn GetAccountBalance(&self, acct: u160) -> u256;
fn GetAccountCode(&self, acct: u160) -> Bytes;
fn GetAccountStorage(&self, key: u256) -> u256;
fn GetAccountOrigStorage(&self, key: u256) -> u256;
fn GetAccountTransientStorage(&self, key: u256) -> u256;
fn IsAccountEmpty(&self, acct: u160) -> bool;

// to be removed in final version
fn AccessedStorage(&self, key: u64) -> bool;
fn AccessedAccount(&self, acct: u64) -> bool;
fn AccessedStorage(&self, key: u256) -> bool;
fn AccessedAccount(&self, acct: u256) -> bool;

fn Transfer(&self, to: u64, value: u64) -> bool;
fn Transfer(&self, to: u160, value: u256) -> bool;
fn SelfDestruct(&self, to: u64);
fn SetAccountStorage(&self, key: u64, value: u64);
fn SetAccountTransientStorage(&self, key: u64, value: u64);
fn SetAccountStorage(&self, key: u256, value: u256);
fn SetAccountTransientStorage(&self, key: u256, value: u256);

fn Log0(data: Bytes);
fn Log1(topic0: u64, data: Bytes);
fn Log2(topic0: u64, topic1: u64, data: Bytes);
fn Log3(topic0: u64, topic1: u64, topic2: u64, data: Bytes);
fn Log4(topic0: u64, topic1: u64, topic2: u64, topic3: u64, data: Bytes);

fn MessageResult(gas: u64, data: Bytes, status: u64, target: u64) -> MessageResult;
fn Create(value: u64, data: Bytes, gas: u64) -> MessageResult;
fn Create2(value: u64, data: Bytes, salt: Bytes, gas: u64) -> MessageResult;
fn Call(gas: u64, to: u64, value: u64, data: Bytes) -> MessageResult;
fn CallCode(gas: u64, to: u64, value: u64, data: Bytes) -> MessageResult;
fn DelegateCall(gas: u64, to: u64, data: Bytes) -> MessageResult;
fn StaticCall(gas: u64, to: u64, data: Bytes) -> MessageResult;
fn MessageResult(gas: u256, data: Bytes, status: u64, target: u64) -> MessageResult;
fn Create(value: u256, data: Bytes, gas: u256) -> MessageResult;
fn Create2(value: u256, data: Bytes, salt: Bytes, gas: u256) -> MessageResult;
fn Call(gas: u256, to: u160, value: u256, data: Bytes) -> MessageResult;
fn CallCode(gas: u256, to: u160, value: u256, data: Bytes) -> MessageResult;
fn DelegateCall(gas: u256, to: u160, data: Bytes) -> MessageResult;
fn StaticCall(gas: u256, to: u160, data: Bytes) -> MessageResult;
}
126 changes: 63 additions & 63 deletions tests/ukm-with-contract/erc_20_token.1.run
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
list_mock GetAccountStorageHook ( 7809087261546347641 ) ukmInt64Result(0);
list_mock GetAccountStorageHook ( 7809087261546347641 ) ukmInt256Result(0);
list_mock SetAccountStorageHook ( 7809087261546347641 , 10000 ) ukmNoResult();
list_mock GetAccountStorageHook ( 7162266444907899391 ) ukmInt64Result(0);
list_mock GetAccountStorageHook ( 7162266444907899391 ) ukmInt256Result(0);
list_mock SetAccountStorageHook ( 7162266444907899391 , 10000 ) ukmNoResult();
list_mock GetAccountStorageHook ( 7162266444907899391 ) ukmInt64Result(10000);
list_mock GetAccountStorageHook ( 7162266444907899391 ) ukmInt64Result(10000);
list_mock GetAccountStorageHook ( 7162266444907899391 ) ukmInt64Result(10000);
list_mock GetAccountStorageHook ( 7162266444907899391 ) ukmInt256Result(10000);
list_mock GetAccountStorageHook ( 7162266444907899391 ) ukmInt256Result(10000);
list_mock GetAccountStorageHook ( 7162266444907899391 ) ukmInt256Result(10000);
list_mock SetAccountStorageHook ( 7162266444907899391 , 9900 ) ukmNoResult();
list_mock GetAccountStorageHook ( 7162266444908917614 ) ukmInt64Result(0);
list_mock GetAccountStorageHook ( 7162266444908917614 ) ukmInt256Result(0);
list_mock SetAccountStorageHook ( 7162266444908917614 , 100 ) ukmNoResult();
list_mock GetAccountStorageHook ( 7162266444907899391 ) ukmInt64Result(9900);
list_mock GetAccountStorageHook ( 7162266444908917614 ) ukmInt64Result(100);
list_mock GetAccountStorageHook ( 7162266444907899391 ) ukmInt256Result(9900);
list_mock GetAccountStorageHook ( 7162266444908917614 ) ukmInt256Result(100);
list_mock SetAccountStorageHook ( 8028228613167873919 , 200 ) ukmNoResult();
list_mock GetAccountStorageHook ( 8028228613167873919 ) ukmInt64Result(200);
list_mock GetAccountStorageHook ( 8028228613167873919 ) ukmInt256Result(200);
list_mock SetAccountStorageHook ( 8028228613167873919 , 0 ) ukmNoResult();
list_mock GetAccountStorageHook ( 7162266444907899391 ) ukmInt64Result(9900);
list_mock GetAccountStorageHook ( 7162266444907899391 ) ukmInt64Result(9900);
list_mock GetAccountStorageHook ( 7162266444907899391 ) ukmInt256Result(9900);
list_mock GetAccountStorageHook ( 7162266444907899391 ) ukmInt256Result(9900);
list_mock SetAccountStorageHook ( 7162266444907899391 , 9700 ) ukmNoResult();
list_mock GetAccountStorageHook ( 7162266444908917614 ) ukmInt64Result(100);
list_mock GetAccountStorageHook ( 7162266444908917614 ) ukmInt256Result(100);
list_mock SetAccountStorageHook ( 7162266444908917614 , 300 ) ukmNoResult();
list_mock GetAccountStorageHook ( 7162266444907899391 ) ukmInt64Result(9700);
list_mock GetAccountStorageHook ( 7162266444908917614 ) ukmInt64Result(300);
list_mock GetAccountStorageHook ( 7162266444907899391 ) ukmInt256Result(9700);
list_mock GetAccountStorageHook ( 7162266444908917614 ) ukmInt256Result(300);

call :: bytes_hooks :: empty;
return_value_to_arg;
push "#init(Uint64)";
push "#init(Uint256)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push 10000_u64;
call :: bytes_hooks :: append_u64;
push 10000_u256;
call :: bytes_hooks :: append_u256;
return_value;
mock CallData;

push_value 1010101_u64;
push_value 1010101_u160;
mock Caller;

call_contract 12345;
Expand All @@ -52,11 +52,11 @@ check_eq 0_u32;

call :: bytes_hooks :: empty;
return_value_to_arg;
push "balanceOf(Uint64)";
push "balanceOf(Uint160)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push 1010101_u64;
call :: bytes_hooks :: append_u64;
push 1010101_u160;
call :: bytes_hooks :: append_u160;
return_value;
mock CallData;

Expand All @@ -68,27 +68,27 @@ push_status;
check_eq 2;

output_to_arg;
call :: test_helpers :: decode_single_u64;
call :: test_helpers :: decode_single_u256;
return_value;

check_eq 10000_u64;
check_eq 10000_u256;



call :: bytes_hooks :: empty;
return_value_to_arg;
push "transfer(Uint64,Uint64)";
push "transfer(Uint160,Uint256)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push 2020202_u64;
call :: bytes_hooks :: append_u64;
push 2020202_u160;
call :: bytes_hooks :: append_u160;
return_value_to_arg;
push 100_u64;
call :: bytes_hooks :: append_u64;
push 100_u256;
call :: bytes_hooks :: append_u256;
return_value;
mock CallData;

push_value 1010101_u64;
push_value 1010101_u160;
mock Caller;

call_contract 12345;
Expand All @@ -108,11 +108,11 @@ check_eq 1_u64;

call :: bytes_hooks :: empty;
return_value_to_arg;
push "balanceOf(Uint64)";
push "balanceOf(Uint160)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push 1010101_u64;
call :: bytes_hooks :: append_u64;
push 1010101_u160;
call :: bytes_hooks :: append_u160;
return_value;
mock CallData;

Expand All @@ -124,21 +124,21 @@ push_status;
check_eq 2;

output_to_arg;
call :: test_helpers :: decode_single_u64;
call :: test_helpers :: decode_single_u256;
return_value;

check_eq 9900_u64;
check_eq 9900_u256;




call :: bytes_hooks :: empty;
return_value_to_arg;
push "balanceOf(Uint64)";
push "balanceOf(Uint160)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push 2020202_u64;
call :: bytes_hooks :: append_u64;
push 2020202_u160;
call :: bytes_hooks :: append_u160;
return_value;
mock CallData;

Expand All @@ -150,10 +150,10 @@ push_status;
check_eq 2;

output_to_arg;
call :: test_helpers :: decode_single_u64;
call :: test_helpers :: decode_single_u256;
return_value;

check_eq 100_u64;
check_eq 100_u256;



Expand All @@ -162,18 +162,18 @@ check_eq 100_u64;

call :: bytes_hooks :: empty;
return_value_to_arg;
push "approve(Uint64,Uint64)";
push "approve(Uint160,Uint256)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push 3030303_u64;
call :: bytes_hooks :: append_u64;
push 3030303_u160;
call :: bytes_hooks :: append_u160;
return_value_to_arg;
push 200_u64;
call :: bytes_hooks :: append_u64;
push 200_u256;
call :: bytes_hooks :: append_u256;
return_value;
mock CallData;

push_value 1010101_u64;
push_value 1010101_u160;
mock Caller;

call_contract 12345;
Expand All @@ -193,21 +193,21 @@ check_eq 1_u64;

call :: bytes_hooks :: empty;
return_value_to_arg;
push "transferFrom(Uint64,Uint64,Uint64)";
push "transferFrom(Uint160,Uint160,Uint256)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push 1010101_u64;
call :: bytes_hooks :: append_u64;
push 1010101_u160;
call :: bytes_hooks :: append_u160;
return_value_to_arg;
push 2020202_u64;
call :: bytes_hooks :: append_u64;
push 2020202_u160;
call :: bytes_hooks :: append_u160;
return_value_to_arg;
push 200_u64;
call :: bytes_hooks :: append_u64;
push 200_u256;
call :: bytes_hooks :: append_u256;
return_value;
mock CallData;

push_value 3030303_u64;
push_value 3030303_u160;
mock Caller;

call_contract 12345;
Expand All @@ -229,11 +229,11 @@ check_eq 1_u64;

call :: bytes_hooks :: empty;
return_value_to_arg;
push "balanceOf(Uint64)";
push "balanceOf(Uint160)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push 1010101_u64;
call :: bytes_hooks :: append_u64;
push 1010101_u160;
call :: bytes_hooks :: append_u160;
return_value;
mock CallData;

Expand All @@ -245,21 +245,21 @@ push_status;
check_eq 2;

output_to_arg;
call :: test_helpers :: decode_single_u64;
call :: test_helpers :: decode_single_u256;
return_value;

check_eq 9700_u64;
check_eq 9700_u256;




call :: bytes_hooks :: empty;
return_value_to_arg;
push "balanceOf(Uint64)";
push "balanceOf(Uint160)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push 2020202_u64;
call :: bytes_hooks :: append_u64;
push 2020202_u160;
call :: bytes_hooks :: append_u160;
return_value;
mock CallData;

Expand All @@ -271,9 +271,9 @@ push_status;
check_eq 2;

output_to_arg;
call :: test_helpers :: decode_single_u64;
call :: test_helpers :: decode_single_u256;
return_value;

check_eq 300_u64
check_eq 300_u256


Loading
Loading