From 8688af82721a2166cbf88b6d597fd958fb0e87a9 Mon Sep 17 00:00:00 2001 From: zeroqn Date: Sat, 30 Apr 2022 01:07:37 +0800 Subject: [PATCH] BREAKING CHANGE: change ckb decimal to 18 (#146) * chore: bump godwoken-scripts and godwoken commit * feat!: change to u256 sudt amount * refactor!: change fee to u128 * fix: tests * chore(Makefile): change fetch-gw-scripts to pr prebuilds * chore(ci): godwoken prebuilds --- .github/workflows/ci.yml | 4 +- Makefile | 3 +- build.rs | 8 +- c/polyjuice.h | 58 +++++++------- c/polyjuice_utils.h | 13 +++- c/sudt_contracts.h | 17 +++-- deps/godwoken-scripts | 2 +- devtools/ci/integration-test.sh | 4 +- polyjuice-tests/src/helper.rs | 75 +++++++------------ .../src/test_cases/account_already_exists.rs | 2 +- polyjuice-tests/src/test_cases/address.rs | 2 +- .../src/test_cases/call_multiple_times.rs | 2 +- .../src/test_cases/call_selfdestruct.rs | 18 +++-- .../src/test_cases/contract_call_contract.rs | 6 +- .../test_cases/contract_create_contract.rs | 2 +- polyjuice-tests/src/test_cases/create2.rs | 8 +- .../src/test_cases/delegatecall.rs | 2 +- polyjuice-tests/src/test_cases/ecrecover.rs | 2 +- polyjuice-tests/src/test_cases/erc20.rs | 6 +- polyjuice-tests/src/test_cases/error.rs | 2 +- .../src/test_cases/eth_addr_reg.rs | 20 ++--- .../src/test_cases/fallback_function.rs | 2 +- .../src/test_cases/get_block_info.rs | 2 +- .../src/test_cases/get_chain_id.rs | 2 +- polyjuice-tests/src/test_cases/heap_memory.rs | 2 +- .../test_cases/invalid_sudt_erc20_proxy.rs | 26 +++++-- .../src/test_cases/parse_log_event.rs | 10 +-- .../src/test_cases/recover_account.rs | 2 +- .../src/test_cases/recursion_contract.rs | 2 +- .../src/test_cases/selfdestruct.rs | 16 ++-- .../src/test_cases/simple_storage.rs | 2 +- .../src/test_cases/simple_transfer.rs | 26 +++---- .../src/test_cases/simple_wallet.rs | 2 +- .../src/test_cases/sudt_erc20_proxy.rs | 16 ++-- 34 files changed, 183 insertions(+), 183 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 60ecf9a6..b43ef2de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,5 +52,7 @@ jobs: with: # github.ref: The branch or tag ref that triggered the workflow run. For branches this is the format refs/heads/, and for tags it is refs/tags/. polyjuice_ref: ${{ github.ref }} - kicker_ref: refs/pull/235/head # https://github.com/RetricSu/godwoken-kicker/pull/235 + gw_prebuild_image_name: ghcr.io/zeroqn/godwoken-prebuilds + gw_prebuild_image_tag: v1.1-feat-change-ckb-decimal-to-18 + kicker_ref: refs/pull/239/head # https://github.com/RetricSu/godwoken-kicker/pull/239 tests_ref: develop # https://github.com/nervosnetwork/godwoken-tests/commits/develop diff --git a/Makefile b/Makefile index 6b830b54..943191a7 100644 --- a/Makefile +++ b/Makefile @@ -240,10 +240,11 @@ contract/sudt-erc20-proxy: # fetch godwoken-scripts from godwoken-prebuilds image, # including meta-contract and sudt-contract +PREBUILDS := ghcr.io/zeroqn/godwoken-prebuilds:v1.1-feat-change-ckb-decimal-to-18 fetch-gw-scripts: mkdir -p build docker run --rm -v `pwd`/build:/build-dir \ - ghcr.io/nervosnetwork/godwoken-prebuilds:v1.1 \ + $(PREBUILDS) \ cp -r /scripts/godwoken-scripts /build-dir \ && echo "Copy godwoken-scripts" diff --git a/build.rs b/build.rs index 500de0e7..0b1a87ff 100644 --- a/build.rs +++ b/build.rs @@ -15,19 +15,19 @@ const CKB_HASH_PERSONALIZATION: &[u8] = b"ckb-default-hash"; const BINARIES: &[(&str, &str)] = &[ ( "generator", - "b1284ae3e3268611368b60c4e7f08b5086cd2d5c5f20c56c94051e689b658f7f", + "6f53704176f5cb3b74cfc72051d7db610b39481698b3624780402332bbe92b44", ), ( "validator", - "9996e062253cd32ebf1b820c391b0103781ff943e66fc937e03cfc817759655f", + "0e224654c6853ca6d0d7d26d0893d507348f5f60f6b20d3e7a6c5fa3e63bd157", ), ( "generator_log", - "235e1c7a126c5e8954a4008a57301f45ad60074ac71e0ccaa730391afb2fddf3", + "81596e5729f40301019c5fa0746f60b950ca57a9103f1ac30687724b7effeea5", ), ( "validator_log", - "8b25482e9c3a7c5070fe356aac24c999b7b60dc142a78f9134f0c58d99b56df4", + "65549e96e013a21abe4fc5a44a9dcbf1020cb9b58e07e1fb6e2161a61bdd1101", ), ]; diff --git a/c/polyjuice.h b/c/polyjuice.h index fcebda3c..400dc10b 100644 --- a/c/polyjuice.h +++ b/c/polyjuice.h @@ -5,23 +5,24 @@ #include #include "ckb_syscalls.h" -#include "godwoken.h" -#include "gw_eth_addr_reg.h" #include #include #include #include +#include "uint256.h" + /* https://stackoverflow.com/a/1545079 */ #pragma push_macro("errno") #undef errno +#include "godwoken.h" +#include "gw_eth_addr_reg.h" #include "gw_syscalls.h" +#include "sudt_utils.h" #pragma pop_macro("errno") #include "common.h" - -#include "sudt_utils.h" #include "polyjuice_errors.h" #include "polyjuice_utils.h" @@ -32,7 +33,6 @@ #endif #include "contracts.h" - #define is_create(kind) ((kind) == EVMC_CREATE || (kind) == EVMC_CREATE2) #define is_special_call(kind) \ ((kind) == EVMC_CALLCODE || (kind) == EVMC_DELEGATECALL) @@ -124,6 +124,7 @@ int load_account_script(gw_context_t* gw_ctx, uint32_t account_id, return 0; } +// TODO: change gas_limit, gas_price, value to u256 /** Message = [ header : [u8; 8] 0xff, 0xff, 0xff, "POLY", call_kind @@ -508,22 +509,22 @@ evmc_uint256be get_balance(struct evmc_host_context* context, gw_reg_addr_t addr = new_reg_addr(address->bytes); - uint128_t value_u128 = 0; + uint256_t value = {0}; int ret = sudt_get_balance(context->gw_ctx, g_sudt_id, /* g_sudt_id account must exists */ - addr, &value_u128); + addr, &value); if (ret != 0) { ckb_debug("sudt_get_balance failed"); context->error_code = FATAL_POLYJUICE; return balance; } - uint8_t* value_ptr = (uint8_t*)(&value_u128); - for (int i = 0; i < 16; i++) { + uint8_t* value_ptr = (uint8_t*)(&value); + for (int i = 0; i < 32; i++) { balance.bytes[31 - i] = *(value_ptr + i); } debug_print_data("address", address->bytes, 20); - debug_print_int("balance", value_u128); + debug_print_data("balance", (uint8_t*)&value, 32); ckb_debug("END get_balance"); return balance; } @@ -533,7 +534,7 @@ void selfdestruct(struct evmc_host_context* context, const evmc_address* beneficiary) { gw_reg_addr_t from_addr = new_reg_addr(address->bytes); - uint128_t balance; + uint256_t balance; int ret = sudt_get_balance(context->gw_ctx, g_sudt_id, /* g_sudt_id account must exists */ from_addr, &balance); @@ -543,7 +544,8 @@ void selfdestruct(struct evmc_host_context* context, return; } - if (balance > 0) { + uint256_t zero = {0}; + if (uint256_cmp(balance, zero) == LARGER) { gw_reg_addr_t to_addr = new_reg_addr(beneficiary->bytes); ret = sudt_transfer(context->gw_ctx, g_sudt_id, @@ -906,18 +908,14 @@ int create_new_account(gw_context_t* ctx, int handle_transfer(gw_context_t* ctx, const evmc_message* msg, bool to_address_is_eoa) { - uint8_t value_u128_bytes[16]; - for (int i = 0; i < 16; i++) { - if (msg->value.bytes[i] != 0) { - ckb_debug("[handle_transfer] transfer value can not larger than u128::max()"); - return FATAL_POLYJUICE; - } - value_u128_bytes[i] = msg->value.bytes[31 - i]; + uint256_t value; + uint8_t* value_ptr = (uint8_t*)&value; + for (int i = 0; i < 32; i++) { + value_ptr[i] = msg->value.bytes[31 - i]; } - uint128_t value_u128 = *(uint128_t*)value_u128_bytes; debug_print_data("[handle_transfer] sender", msg->sender.bytes, 20); debug_print_data("[handle_transfer] destination", msg->destination.bytes, 20); - debug_print_int("[handle_transfer] msg->value", value_u128); + debug_print_data("[handle_transfer] msg->value", (uint8_t*)&value, 32); if (msg->kind == EVMC_CALL && memcmp(msg->sender.bytes, g_tx_origin.bytes, 20) == 0 @@ -929,13 +927,11 @@ int handle_transfer(gw_context_t* ctx, gw_reg_addr_t from_addr = new_reg_addr(msg->sender.bytes); gw_reg_addr_t to_addr = new_reg_addr(msg->destination.bytes); - if (value_u128 == 0) { + uint256_t zero = {0}; + if (uint256_cmp(value, zero) == EQUAL) { return 0; } - int ret = sudt_transfer(ctx, g_sudt_id, - from_addr, - to_addr, - value_u128); + int ret = sudt_transfer(ctx, g_sudt_id, from_addr, to_addr, value); if (ret != 0) { ckb_debug("[handle_transfer] sudt_transfer failed"); return ret; @@ -1368,9 +1364,11 @@ int run_polyjuice() { gw_reg_addr_t sender_addr = new_reg_addr(msg.sender.bytes); - ret = sudt_pay_fee(&context, - g_sudt_id, /* g_sudt_id must already exists */ - sender_addr, fee); + uint256_t fee_u256 = {0}; + memcpy((uint8_t *)(&fee_u256), (uint8_t*)(&fee), 16); + + ret = sudt_pay_fee(&context, g_sudt_id, /* g_sudt_id must already exists */ + sender_addr, fee_u256); if (ret != 0) { debug_print_int("[run_polyjuice] pay fee to block_producer failed", ret); return clean_evmc_result_and_return(&res, ret); @@ -1378,7 +1376,7 @@ int run_polyjuice() { // call the SYS_PAY_FEE syscall to record the fee // NOTICE: this function do not actually execute the transfer of assets - ret = sys_pay_fee(&context, sender_addr, g_sudt_id, fee); + ret = sys_pay_fee(&context, sender_addr, g_sudt_id, fee_u256); if (ret != 0) { debug_print_int("[run_polyjuice] Record fee payment failed", ret); return clean_evmc_result_and_return(&res, ret); diff --git a/c/polyjuice_utils.h b/c/polyjuice_utils.h index ffc1a01c..7c413de9 100644 --- a/c/polyjuice_utils.h +++ b/c/polyjuice_utils.h @@ -108,7 +108,6 @@ int build_script(const uint8_t code_hash[32], const uint8_t hash_type, return 0; } - /** * @param script_hash should have been initialed as zero_hash = {0} * @@ -218,7 +217,7 @@ void rlp_encode_sender_and_nonce(const evmc_address *sender, uint32_t nonce, data[0] = *data_len - 1 + RLP_LIST_OFFSET; } -/* Parse uint32_t/uint128_t from big endian byte32 data */ +/* Parse uint32_t/uint64_t/uint128_t/uint256_t from big endian byte32 data */ int parse_integer(const uint8_t data_be[32], uint8_t *value, size_t value_size) { if (value_size > 32) { @@ -246,6 +245,9 @@ int parse_u64(const uint8_t data_be[32], uint64_t *value) { int parse_u128(const uint8_t data_be[32], uint128_t *value) { return parse_integer(data_be, (uint8_t *)value, sizeof(uint128_t)); } +int parse_u256(const uint8_t data_be[32], uint256_t *value) { + return parse_integer(data_be, (uint8_t *)value, sizeof(uint256_t)); +} /* serialize uint64_t to big endian byte32 */ void put_u64(uint64_t value, uint8_t *output) { @@ -263,6 +265,13 @@ void put_u128(uint128_t value, uint8_t *output) { } } +void put_u256(uint256_t value, uint8_t *output) { + uint8_t *value_le = (uint8_t *)(&value); + for (size_t i = 0; i < 32; i++) { + *(output + 31 - i) = *(value_le + i); + } +} + /* If it is a fatal error, terminate the whole process. * ==== * - gw_errors.h GW_FATAIL_xxx [50, 80) diff --git a/c/sudt_contracts.h b/c/sudt_contracts.h index f2b50b27..88c01b7d 100644 --- a/c/sudt_contracts.h +++ b/c/sudt_contracts.h @@ -59,8 +59,8 @@ int balance_of_any_sudt(gw_context_t* ctx, const uint8_t* code_data, evmc_address address = *((evmc_address*)(input_src + 32 + 12)); gw_reg_addr_t addr = new_reg_addr(address.bytes); - - uint128_t balance; + + uint256_t balance; ret = sudt_get_balance(ctx, sudt_id, addr, &balance); if (ret == GW_ERROR_NOT_FOUND) { debug_print_int("[balance_of_any_sudt] sudt account not found", sudt_id); @@ -73,7 +73,7 @@ int balance_of_any_sudt(gw_context_t* ctx, const uint8_t* code_data, return ERROR_BALANCE_OF_ANY_SUDT; } } - put_u128(balance, *output); + put_u256(balance, *output); return 0; } @@ -118,8 +118,8 @@ int total_supply_of_any_sudt(gw_context_t* ctx, const uint8_t* code_data, *output_size = 32; memset(*output, 0, 32); - uint8_t total_supply_le[32] = {0}; - ret = sudt_get_total_supply(ctx, sudt_id, total_supply_le); + uint256_t total_supply_le = {0}; + ret = sudt_get_total_supply(ctx, sudt_id, &total_supply_le); if (ret == GW_ERROR_NOT_FOUND) { debug_print_int("sudt account not found", sudt_id); return 0; @@ -132,8 +132,9 @@ int total_supply_of_any_sudt(gw_context_t* ctx, const uint8_t* code_data, } } + uint8_t* total_supply_le_bytes = (uint8_t*)&total_supply_le; for (size_t i = 0; i < 32; i++) { - (*output)[31 - i] = total_supply_le[i]; + (*output)[31 - i] = total_supply_le_bytes[i]; } return 0; } @@ -198,12 +199,12 @@ int transfer_to_any_sudt(gw_context_t* ctx, const uint8_t* code_data, } uint32_t sudt_id = 0; - uint128_t amount = 0; + uint256_t amount = {0}; ret = parse_u32(input_src, &sudt_id); if (ret != 0) { return ERROR_TRANSFER_TO_ANY_SUDT; } - ret = parse_u128(input_src + 96, &amount); + ret = parse_u256(input_src + 96, &amount); if (ret != 0) { return ERROR_TRANSFER_TO_ANY_SUDT; } diff --git a/deps/godwoken-scripts b/deps/godwoken-scripts index a23886bb..fddb1ffd 160000 --- a/deps/godwoken-scripts +++ b/deps/godwoken-scripts @@ -1 +1 @@ -Subproject commit a23886bb6cb0381e0d58beaa0a5261a0e403c4fd +Subproject commit fddb1ffd8037e3b85e0d82febff4527d1faae752 diff --git a/devtools/ci/integration-test.sh b/devtools/ci/integration-test.sh index 8fd66c51..aeadba8d 100644 --- a/devtools/ci/integration-test.sh +++ b/devtools/ci/integration-test.sh @@ -15,8 +15,8 @@ else git clone --depth=1 https://github.com/nervosnetwork/godwoken.git $GODWOKEN_DIR fi cd $GODWOKEN_DIR -# checkout https://github.com/nervosnetwork/godwoken/pull/659/head -git fetch origin 0dd1500455ca81c23addadff05399925921aa352 +# checkout https://github.com/nervosnetwork/godwoken/pull/675/merge +git fetch origin pull/675/merge git checkout FETCH_HEAD git submodule update --init --recursive --depth=1 diff --git a/polyjuice-tests/src/helper.rs b/polyjuice-tests/src/helper.rs index eb7692a2..1ac03035 100644 --- a/polyjuice-tests/src/helper.rs +++ b/polyjuice-tests/src/helper.rs @@ -26,9 +26,10 @@ use gw_types::{ offchain::RunResult, packed::{ AllowedTypeHash, BatchSetMapping, BlockInfo, Fee, LogItem, RawL2Transaction, RollupConfig, - Script, Uint64, + Script, SetMapping, Uint64, }, prelude::*, + U256, }; use gw_types::{ offchain::RollupContext, @@ -126,13 +127,13 @@ pub enum Log { sudt_id: u32, from_addr: RegistryAddress, to_addr: RegistryAddress, - amount: u128, + amount: U256, }, SudtPayFee { sudt_id: u32, from_addr: RegistryAddress, block_producer_addr: RegistryAddress, - amount: u128, + amount: U256, }, PolyjuiceSystem { gas_used: u64, @@ -147,13 +148,13 @@ pub enum Log { }, } -fn parse_sudt_log_data(data: &[u8]) -> (RegistryAddress, RegistryAddress, u128) { +fn parse_sudt_log_data(data: &[u8]) -> (RegistryAddress, RegistryAddress, U256) { let from_addr = RegistryAddress::from_slice(&data[0..28]).expect("parse from_addr"); let to_addr = RegistryAddress::from_slice(&data[28..56]).expect("parse to_addr"); - let mut u128_bytes = [0u8; 16]; - u128_bytes.copy_from_slice(&data[56..56 + 16]); - let amount = u128::from_le_bytes(u128_bytes); + let mut u256_bytes = [0u8; 32]; + u256_bytes.copy_from_slice(&data[56..56 + 32]); + let amount = U256::from_little_endian(&mut u256_bytes); (from_addr, to_addr, amount) } @@ -164,7 +165,7 @@ pub fn parse_log(item: &LogItem) -> Log { match service_flag { GW_LOG_SUDT_TRANSFER => { let sudt_id: u32 = item.account_id().unpack(); - if data.len() != (28 + 28 + 16) { + if data.len() != (28 + 28 + 32) { panic!("Invalid data length: {}", data.len()); } let (from_addr, to_addr, amount) = parse_sudt_log_data(data); @@ -177,7 +178,7 @@ pub fn parse_log(item: &LogItem) -> Log { } GW_LOG_SUDT_PAY_FEE => { let sudt_id: u32 = item.account_id().unpack(); - if data.len() != (28 + 28 + 16) { + if data.len() != (28 + 28 + 32) { panic!("Invalid data length: {}", data.len()); } let (from_addr, block_producer_addr, amount) = parse_sudt_log_data(data); @@ -686,7 +687,7 @@ pub(crate) fn create_block_producer(state: &mut DummyState) -> RegistryAddress { pub(crate) fn create_eth_eoa_account( state: &mut DummyState, eth_address: &[u8; 20], - mint_ckb: u128, + mint_ckb: U256, ) -> (u32, [u8; 32]) { let script = build_eth_l2_script(eth_address); let script_hash = script.hash(); @@ -736,38 +737,6 @@ pub(crate) fn register_eoa_account( .expect("map reg addr to script hash"); } -#[derive(Default)] -struct SetMappingArgsBuilder { - method: u32, - gw_script_hash: [u8; 32], - fee: u64, -} -impl SetMappingArgsBuilder { - /// Set the SetMappingArgs builder's method. - fn method(mut self, method: u32) -> Self { - self.method = method; - self - } - /// Set the SetMappingArgs builder's gw script hash. - fn gw_script_hash(mut self, gw_script_hash: [u8; 32]) -> Self { - self.gw_script_hash = gw_script_hash; - self - } - /// Set the set mapping args‘s fee. - fn set_fee(mut self, fee: u64) -> Self { - self.fee = fee; - self - } - fn build(self) -> Vec { - let mut output: Vec = vec![0u8; 4]; - output[0..4].copy_from_slice(&self.method.to_le_bytes()[..]); - output.extend(self.gw_script_hash); - output.extend(ETH_REGISTRY_ACCOUNT_ID.to_le_bytes()); - output.extend(&self.fee.to_le_bytes()[..]); - output - } -} - pub enum SetMappingArgs { One(H256), Batch(Vec), @@ -784,16 +753,24 @@ pub(crate) fn eth_address_regiser( set_mapping_args: SetMappingArgs, ) -> Result { let args = match set_mapping_args { - SetMappingArgs::One(gw_script_hash) => SetMappingArgsBuilder::default() - .method(2u32) - .gw_script_hash(gw_script_hash.into()) - .set_fee(1000) - .build() - .pack(), + SetMappingArgs::One(gw_script_hash) => { + let fee = Fee::new_builder() + .registry_id(ETH_REGISTRY_ACCOUNT_ID.pack()) + .amount(1000u128.pack()) + .build(); + let set_mapping = SetMapping::new_builder() + .fee(fee) + .gw_script_hash(gw_script_hash.pack()) + .build(); + let args = ETHAddrRegArgs::new_builder() + .set(ETHAddrRegArgsUnion::SetMapping(set_mapping)) + .build(); + args.as_bytes().pack() + } SetMappingArgs::Batch(gw_script_hashes) => { let fee = Fee::new_builder() .registry_id(ETH_REGISTRY_ACCOUNT_ID.pack()) - .amount(1000u64.pack()) + .amount(1000u128.pack()) .build(); let batch_set_mapping = BatchSetMapping::new_builder() .fee(fee) diff --git a/polyjuice-tests/src/test_cases/account_already_exists.rs b/polyjuice-tests/src/test_cases/account_already_exists.rs index 08c534a0..c52a86fe 100644 --- a/polyjuice-tests/src/test_cases/account_already_exists.rs +++ b/polyjuice-tests/src/test_cases/account_already_exists.rs @@ -17,7 +17,7 @@ fn test_account_already_exists() { let from_eth_address = [1u8; 20]; let (from_id, _from_script_hash) = - helper::create_eth_eoa_account(&mut state, &from_eth_address, 400000); + helper::create_eth_eoa_account(&mut state, &from_eth_address, 400000u64.into()); let created_ss_account_script = new_contract_account_script_with_nonce(&from_eth_address, 0); let created_ss_account_id = state diff --git a/polyjuice-tests/src/test_cases/address.rs b/polyjuice-tests/src/test_cases/address.rs index d64eaa68..ff394f0d 100644 --- a/polyjuice-tests/src/test_cases/address.rs +++ b/polyjuice-tests/src/test_cases/address.rs @@ -18,7 +18,7 @@ fn test_get_contract_code() { let from_eth_address = [1u8; 20]; let (from_id, _from_script_hash) = - helper::create_eth_eoa_account(&mut state, &from_eth_address, 400000); + helper::create_eth_eoa_account(&mut state, &from_eth_address, 400000u64.into()); // Deploy contract let mut block_number = 1; diff --git a/polyjuice-tests/src/test_cases/call_multiple_times.rs b/polyjuice-tests/src/test_cases/call_multiple_times.rs index 087e7fc2..27a906e9 100644 --- a/polyjuice-tests/src/test_cases/call_multiple_times.rs +++ b/polyjuice-tests/src/test_cases/call_multiple_times.rs @@ -20,7 +20,7 @@ fn test_call_multiple_times() { let block_producer_id = crate::helper::create_block_producer(&mut state); let from_eth_address = [1u8; 20]; - let (from_id, _) = create_eth_eoa_account(&mut state, &from_eth_address, 300000); + let (from_id, _) = create_eth_eoa_account(&mut state, &from_eth_address, 300000u64.into()); // Deploy two SimpleStorage let mut block_number = 1; diff --git a/polyjuice-tests/src/test_cases/call_selfdestruct.rs b/polyjuice-tests/src/test_cases/call_selfdestruct.rs index 19cf5cbf..d7e616bb 100644 --- a/polyjuice-tests/src/test_cases/call_selfdestruct.rs +++ b/polyjuice-tests/src/test_cases/call_selfdestruct.rs @@ -11,7 +11,7 @@ use gw_common::{ use gw_generator::traits::StateExt; use gw_store::chain_view::ChainView; use gw_store::traits::chain_store::ChainStore; -use gw_types::{bytes::Bytes, packed::RawL2Transaction, prelude::*}; +use gw_types::{bytes::Bytes, packed::RawL2Transaction, prelude::*, U256}; const SD_INIT_CODE: &str = include_str!("./evm-contracts/SelfDestruct.bin"); const CALL_SD_INIT_CODE: &str = include_str!("./evm-contracts/CallSelfDestruct.bin"); @@ -22,18 +22,20 @@ fn test_selfdestruct() { let block_producer_id = helper::create_block_producer(&mut state); let from_eth_address = [1u8; 20]; - let (from_id, _) = helper::create_eth_eoa_account(&mut state, &from_eth_address, 300000); + let (from_id, _) = + helper::create_eth_eoa_account(&mut state, &from_eth_address, 300000u64.into()); let beneficiary_eth_addr = [2u8; 20]; let beneficiary_ethabi_addr = eth_addr_to_ethabi_addr(&beneficiary_eth_addr); - let (_beneficiary_id, _) = helper::create_eth_eoa_account(&mut state, &beneficiary_eth_addr, 0); + let (_beneficiary_id, _) = + helper::create_eth_eoa_account(&mut state, &beneficiary_eth_addr, 0u64.into()); let beneficiary_address = RegistryAddress::new(ETH_REGISTRY_ACCOUNT_ID, beneficiary_eth_addr.to_vec()); assert_eq!( state .get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &beneficiary_address) .unwrap(), - 0 + U256::zero() ); // deploy SelfDestruct @@ -71,13 +73,13 @@ fn test_selfdestruct() { state .get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &sd_address) .unwrap(), - 200 + U256::from(200u64) ); assert_eq!( state .get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &beneficiary_address) .unwrap(), - 0 + U256::zero() ); // deploy CallSelfDestruct @@ -152,13 +154,13 @@ fn test_selfdestruct() { state .get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &sd_address) .unwrap(), - 0 + U256::zero() ); assert_eq!( state .get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &beneficiary_address) .unwrap(), - 200 + U256::from(200u64) ); block_number += 1; diff --git a/polyjuice-tests/src/test_cases/contract_call_contract.rs b/polyjuice-tests/src/test_cases/contract_call_contract.rs index 5006f495..bc225523 100644 --- a/polyjuice-tests/src/test_cases/contract_call_contract.rs +++ b/polyjuice-tests/src/test_cases/contract_call_contract.rs @@ -23,7 +23,7 @@ fn test_contract_call_contract() { let from_eth_address = [1u8; 20]; let (from_id, _from_script_hash) = - helper::create_eth_eoa_account(&mut state, &from_eth_address, 200000); + helper::create_eth_eoa_account(&mut state, &from_eth_address, 200000u64.into()); // Deploy SimpleStorage let mut block_number = 1; @@ -149,7 +149,7 @@ fn test_contract_call_non_exists_contract() { let from_eth_address = [1u8; 20]; let (from_id, _from_script_hash) = - helper::create_eth_eoa_account(&mut state, &from_eth_address, 200000); + helper::create_eth_eoa_account(&mut state, &from_eth_address, 200000u64.into()); // Deploy CallNonExistsContract let block_number = 1; @@ -222,7 +222,7 @@ fn test_contract_call_non_exists_contract() { { // Call CallNonExistsContract.rawCall(address eoa_addr) let eoa_addr = [2u8; 20]; - let (_, _script_hash) = create_eth_eoa_account(&mut state, &eoa_addr, 0); + let (_, _script_hash) = create_eth_eoa_account(&mut state, &eoa_addr, 0u64.into()); let eoa_ethabi_addr = eth_addr_to_ethabi_addr(&eoa_addr); let input = hex::decode(format!("56c94e70{}", hex::encode(eoa_ethabi_addr))).unwrap(); println!("{}", hex::encode(&input)); diff --git a/polyjuice-tests/src/test_cases/contract_create_contract.rs b/polyjuice-tests/src/test_cases/contract_create_contract.rs index e36ce39e..9378cb46 100644 --- a/polyjuice-tests/src/test_cases/contract_create_contract.rs +++ b/polyjuice-tests/src/test_cases/contract_create_contract.rs @@ -20,7 +20,7 @@ fn test_contract_create_contract() { let from_eth_address = [1u8; 20]; let (from_id, _from_script_hash) = - helper::create_eth_eoa_account(&mut state, &from_eth_address, 200000); + helper::create_eth_eoa_account(&mut state, &from_eth_address, 200000u64.into()); // let account_sub = MockContractInfo::create(&from_eth_address, 0); // dbg!(hex::encode(&account_sub.eth_addr)); // account_sub.mapping_registry_address_to_script_hash(&mut state); diff --git a/polyjuice-tests/src/test_cases/create2.rs b/polyjuice-tests/src/test_cases/create2.rs index aafd4772..39b100d2 100644 --- a/polyjuice-tests/src/test_cases/create2.rs +++ b/polyjuice-tests/src/test_cases/create2.rs @@ -10,7 +10,7 @@ use gw_common::{builtins::ETH_REGISTRY_ACCOUNT_ID, state::State}; use gw_generator::traits::StateExt; use gw_store::chain_view::ChainView; use gw_store::traits::chain_store::ChainStore; -use gw_types::{bytes::Bytes, packed::RawL2Transaction, prelude::*}; +use gw_types::{bytes::Bytes, packed::RawL2Transaction, prelude::*, U256}; const SS_INIT_CODE: &str = include_str!("./evm-contracts/SimpleStorage.bin"); const CREATE2_IMPL_CODE: &str = include_str!("./evm-contracts/Create2Impl.bin"); @@ -22,7 +22,7 @@ fn test_create2() { let from_eth_address = [1u8; 20]; let (from_id, _from_script_hash) = - helper::create_eth_eoa_account(&mut state, &from_eth_address, 2000000); + helper::create_eth_eoa_account(&mut state, &from_eth_address, 2000000u64.into()); // Deploy CREATE2_IMPL_CODE let mut block_number = 1; @@ -59,7 +59,7 @@ fn test_create2() { let create2_contract_balance = state .get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &address) .unwrap(); - assert_eq!(create2_contract_balance, 0); + assert_eq!(create2_contract_balance, U256::zero()); let input_value_u128: u128 = 0x9a; // bytes32 salt @@ -128,7 +128,7 @@ fn test_create2() { let create2_account_balance = state .get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &address) .unwrap(); - assert_eq!(create2_account_balance, input_value_u128); + assert_eq!(create2_account_balance, U256::from(input_value_u128)); let run_result = simple_storage_get( &store, diff --git a/polyjuice-tests/src/test_cases/delegatecall.rs b/polyjuice-tests/src/test_cases/delegatecall.rs index ece8eea6..db1b0939 100644 --- a/polyjuice-tests/src/test_cases/delegatecall.rs +++ b/polyjuice-tests/src/test_cases/delegatecall.rs @@ -22,7 +22,7 @@ fn test_delegatecall() { let from_eth_address = [1u8; 20]; let (from_id, _from_script_hash) = - helper::create_eth_eoa_account(&mut state, &from_eth_address, 280000); + helper::create_eth_eoa_account(&mut state, &from_eth_address, 280000u64.into()); // Deploy SimpleStorage let mut block_number = 1; diff --git a/polyjuice-tests/src/test_cases/ecrecover.rs b/polyjuice-tests/src/test_cases/ecrecover.rs index c081a5b4..70cba868 100644 --- a/polyjuice-tests/src/test_cases/ecrecover.rs +++ b/polyjuice-tests/src/test_cases/ecrecover.rs @@ -20,7 +20,7 @@ fn test_ecrecover() { let from_eth_address = [1u8; 20]; let (from_id, _from_script_hash) = - helper::create_eth_eoa_account(&mut state, &from_eth_address, 200000); + helper::create_eth_eoa_account(&mut state, &from_eth_address, 200000u64.into()); // Deploy HeadTail Contract let run_result = deploy( diff --git a/polyjuice-tests/src/test_cases/erc20.rs b/polyjuice-tests/src/test_cases/erc20.rs index 436f072b..9b06fd7f 100644 --- a/polyjuice-tests/src/test_cases/erc20.rs +++ b/polyjuice-tests/src/test_cases/erc20.rs @@ -20,15 +20,15 @@ fn test_erc20() { let from_eth_address1 = [1u8; 20]; let (from_id1, _from_script_hash1) = - helper::create_eth_eoa_account(&mut state, &from_eth_address1, 2000000); + helper::create_eth_eoa_account(&mut state, &from_eth_address1, 2000000u64.into()); let from_eth_address2 = [2u8; 20]; let (_from_id2, _from_script_hash2) = - helper::create_eth_eoa_account(&mut state, &from_eth_address2, 0); + helper::create_eth_eoa_account(&mut state, &from_eth_address2, 0u64.into()); let from_eth_address3 = [3u8; 20]; let (from_id3, _from_script_hash3) = - helper::create_eth_eoa_account(&mut state, &from_eth_address3, 80000); + helper::create_eth_eoa_account(&mut state, &from_eth_address3, 80000u64.into()); // Deploy ERC20 let run_result = deploy( diff --git a/polyjuice-tests/src/test_cases/error.rs b/polyjuice-tests/src/test_cases/error.rs index 2d117a5d..c8b6c6d9 100644 --- a/polyjuice-tests/src/test_cases/error.rs +++ b/polyjuice-tests/src/test_cases/error.rs @@ -21,7 +21,7 @@ fn test_error_handling() { // init accounts let from_eth_address = [1u8; 20]; let (from_id, _from_script_hash) = - helper::create_eth_eoa_account(&mut state, &from_eth_address, 400000); + helper::create_eth_eoa_account(&mut state, &from_eth_address, 400000u64.into()); // deploy Error contract let run_result = helper::deploy( diff --git a/polyjuice-tests/src/test_cases/eth_addr_reg.rs b/polyjuice-tests/src/test_cases/eth_addr_reg.rs index ca62b717..afde5b2a 100644 --- a/polyjuice-tests/src/test_cases/eth_addr_reg.rs +++ b/polyjuice-tests/src/test_cases/eth_addr_reg.rs @@ -5,7 +5,7 @@ use crate::helper::{ use gw_common::{registry_address::RegistryAddress, state::State}; use gw_generator::{error::TransactionError, traits::StateExt}; use gw_store::{chain_view::ChainView, traits::chain_store::ChainStore}; -use gw_types::{packed::RawL2Transaction, prelude::*}; +use gw_types::{packed::RawL2Transaction, prelude::*, U256}; const SS_INIT_CODE: &str = include_str!("./evm-contracts/SimpleStorage.bin"); @@ -61,7 +61,7 @@ fn test_update_eth_addr_reg_by_contract() { // init accounts let from_eth_address = [1u8; 20]; let (from_id, _from_script_hash) = - helper::create_eth_eoa_account(&mut state, &from_eth_address, 400000); + helper::create_eth_eoa_account(&mut state, &from_eth_address, U256::from(400000u64)); // create a new EOA which is not registered let eth_eoa_address = [0xeeu8; 20]; @@ -75,16 +75,16 @@ fn test_update_eth_addr_reg_by_contract() { state .get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &address) .unwrap(), - 0u128 + U256::zero() ); state /* mint CKB to pay fee */ - .mint_sudt(CKB_SUDT_ACCOUNT_ID, &address, 52000) + .mint_sudt(CKB_SUDT_ACCOUNT_ID, &address, U256::from(52000u64)) .unwrap(); assert_eq!( state .get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &address) .unwrap(), - 52000u128 + U256::from(52000u128) ); // update_eth_address_registry by `ETH Address Registry` layer2 contract @@ -106,7 +106,7 @@ fn test_update_eth_addr_reg_by_contract() { state .get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &address) .unwrap(), - 51000u128 + U256::from(51000u128) ); // try to register the same account again @@ -199,7 +199,7 @@ fn test_batch_set_mapping_by_contract() { // init accounts let from_eth_address = [1u8; 20]; let (from_id, _from_script_hash) = - helper::create_eth_eoa_account(&mut state, &from_eth_address, 400000); + helper::create_eth_eoa_account(&mut state, &from_eth_address, U256::from(400000u64)); // create new EOAs which is not registered let eth_eoa_addresses = vec![[0xeeu8; 20], [0xefu8; 20]]; @@ -215,16 +215,16 @@ fn test_batch_set_mapping_by_contract() { state .get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &address) .unwrap(), - 0u128 + U256::zero() ); state /* mint CKB to pay fee */ - .mint_sudt(CKB_SUDT_ACCOUNT_ID, &address, 200000) + .mint_sudt(CKB_SUDT_ACCOUNT_ID, &address, U256::from(200000u64)) .unwrap(); assert_eq!( state .get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &address) .unwrap(), - 200000u128 + U256::from(200000u128) ); } diff --git a/polyjuice-tests/src/test_cases/fallback_function.rs b/polyjuice-tests/src/test_cases/fallback_function.rs index a192bef5..613544f6 100644 --- a/polyjuice-tests/src/test_cases/fallback_function.rs +++ b/polyjuice-tests/src/test_cases/fallback_function.rs @@ -20,7 +20,7 @@ fn test_fallback_function() { let from_eth_address = [1u8; 20]; let (from_id, _from_script_hash) = - crate::helper::create_eth_eoa_account(&mut state, &from_eth_address, 200000); + crate::helper::create_eth_eoa_account(&mut state, &from_eth_address, 200000u64.into()); { // Deploy FallbackFunction Contract diff --git a/polyjuice-tests/src/test_cases/get_block_info.rs b/polyjuice-tests/src/test_cases/get_block_info.rs index 8b50d933..1fb03bc2 100644 --- a/polyjuice-tests/src/test_cases/get_block_info.rs +++ b/polyjuice-tests/src/test_cases/get_block_info.rs @@ -42,7 +42,7 @@ fn test_get_block_info() { let from_eth_address = [1u8; 20]; let (from_id, _from_script_hash) = - crate::helper::create_eth_eoa_account(&mut state, &from_eth_address, 400000); + crate::helper::create_eth_eoa_account(&mut state, &from_eth_address, 400000u64.into()); // Deploy BlockInfo let mut block_number = 0x05; diff --git a/polyjuice-tests/src/test_cases/get_chain_id.rs b/polyjuice-tests/src/test_cases/get_chain_id.rs index bc0a473d..db0b8e34 100644 --- a/polyjuice-tests/src/test_cases/get_chain_id.rs +++ b/polyjuice-tests/src/test_cases/get_chain_id.rs @@ -20,7 +20,7 @@ fn test_get_chain_id() { let from_eth_address = [1u8; 20]; let (from_id, from_script_hash) = - crate::helper::create_eth_eoa_account(&mut state, &from_eth_address, 200000); + crate::helper::create_eth_eoa_account(&mut state, &from_eth_address, 200000u64.into()); let address = state .get_registry_address_by_script_hash(ETH_REGISTRY_ACCOUNT_ID, &from_script_hash.into()) .unwrap() diff --git a/polyjuice-tests/src/test_cases/heap_memory.rs b/polyjuice-tests/src/test_cases/heap_memory.rs index c90e9f95..91593d3b 100644 --- a/polyjuice-tests/src/test_cases/heap_memory.rs +++ b/polyjuice-tests/src/test_cases/heap_memory.rs @@ -21,7 +21,7 @@ fn test_heap_momory() { let from_eth_address = [1u8; 20]; let (from_id, _from_script_hash) = - helper::create_eth_eoa_account(&mut state, &from_eth_address, 20000000); + helper::create_eth_eoa_account(&mut state, &from_eth_address, 20000000u64.into()); let mut block_number = 1; // Deploy Memory Contract diff --git a/polyjuice-tests/src/test_cases/invalid_sudt_erc20_proxy.rs b/polyjuice-tests/src/test_cases/invalid_sudt_erc20_proxy.rs index 8aa5b96e..17c89773 100644 --- a/polyjuice-tests/src/test_cases/invalid_sudt_erc20_proxy.rs +++ b/polyjuice-tests/src/test_cases/invalid_sudt_erc20_proxy.rs @@ -9,7 +9,7 @@ use gw_common::{builtins::ETH_REGISTRY_ACCOUNT_ID, state::State}; use gw_generator::{error::TransactionError, traits::StateExt}; use gw_store::chain_view::ChainView; use gw_store::traits::chain_store::ChainStore; -use gw_types::{bytes::Bytes, packed::RawL2Transaction, prelude::*}; +use gw_types::{bytes::Bytes, packed::RawL2Transaction, prelude::*, U256}; const INVALID_SUDT_ERC20_PROXY_CODE: &str = include_str!("./evm-contracts/InvalidSudtERC20Proxy.bin"); @@ -24,7 +24,7 @@ fn test_invalid_sudt_erc20_proxy() { let from_eth_address1 = [1u8; 20]; let (from_id1, from_script_hash1) = - helper::create_eth_eoa_account(&mut state, &from_eth_address1, 2000000); + helper::create_eth_eoa_account(&mut state, &from_eth_address1, 2000000u64.into()); let address1 = state .get_registry_address_by_script_hash(ETH_REGISTRY_ACCOUNT_ID, &from_script_hash1.into()) .unwrap() @@ -32,7 +32,7 @@ fn test_invalid_sudt_erc20_proxy() { let from_eth_address2 = [2u8; 20]; let (_from_id2, from_script_hash2) = - helper::create_eth_eoa_account(&mut state, &from_eth_address2, 2000000); + helper::create_eth_eoa_account(&mut state, &from_eth_address2, 2000000u64.into()); let address2 = state .get_registry_address_by_script_hash(ETH_REGISTRY_ACCOUNT_ID, &from_script_hash2.into()) .unwrap() @@ -40,7 +40,7 @@ fn test_invalid_sudt_erc20_proxy() { let from_eth_address3 = [3u8; 20]; let (_from_id3, _from_script_hash3) = - helper::create_eth_eoa_account(&mut state, &from_eth_address3, 2000000); + helper::create_eth_eoa_account(&mut state, &from_eth_address3, 2000000u64.into()); // Deploy InvalidSudtERC20Proxy // ethabi encode params -v string "test" -v string "tt" -v uint256 000000000000000000000000000000000000000204fce5e3e250261100000000 -v uint256 0000000000000000000000000000000000000000000000000000000000000001 @@ -77,15 +77,25 @@ fn test_invalid_sudt_erc20_proxy() { let eoa2_hex = hex::encode(eth_addr_to_ethabi_addr(&from_eth_address2)); state - .mint_sudt(new_sudt_id, &address1, 160000000000000000000000000000u128) + .mint_sudt( + new_sudt_id, + &address1, + U256::from(160000000000000000000000000000u128), + ) .unwrap(); assert_eq!( state.get_sudt_balance(new_sudt_id, &address1).unwrap(), - 160000000000000000000000000000u128 + U256::from(160000000000000000000000000000u128) + ); + assert_eq!( + state.get_sudt_balance(new_sudt_id, &address2).unwrap(), + U256::zero() + ); + assert_eq!( + state.get_sudt_balance(new_sudt_id, &address2).unwrap(), + U256::zero() ); - assert_eq!(state.get_sudt_balance(new_sudt_id, &address2).unwrap(), 0); - assert_eq!(state.get_sudt_balance(new_sudt_id, &address2).unwrap(), 0); for (_idx, (from_id, args_str, success, return_data_str)) in [ // balanceOf(eoa1) ( diff --git a/polyjuice-tests/src/test_cases/parse_log_event.rs b/polyjuice-tests/src/test_cases/parse_log_event.rs index e9dcafb3..195972f0 100644 --- a/polyjuice-tests/src/test_cases/parse_log_event.rs +++ b/polyjuice-tests/src/test_cases/parse_log_event.rs @@ -9,7 +9,7 @@ use gw_common::{builtins::ETH_REGISTRY_ACCOUNT_ID, state::State}; use gw_generator::traits::StateExt; use gw_store::chain_view::ChainView; use gw_store::traits::chain_store::ChainStore; -use gw_types::{bytes::Bytes, packed::RawL2Transaction, prelude::*}; +use gw_types::{bytes::Bytes, packed::RawL2Transaction, prelude::*, U256}; const INIT_CODE: &str = include_str!("./evm-contracts/LogEvents.bin"); @@ -20,7 +20,7 @@ fn test_parse_log_event() { let from_eth_addr = [1u8; 20]; let (from_id, from_script_hash) = - crate::helper::create_eth_eoa_account(&mut state, &from_eth_addr, 200000); + crate::helper::create_eth_eoa_account(&mut state, &from_eth_addr, 200000u64.into()); let address = state .get_registry_address_by_script_hash(ETH_REGISTRY_ACCOUNT_ID, &from_script_hash.into()) .unwrap() @@ -29,7 +29,7 @@ fn test_parse_log_event() { let from_balance1 = state .get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &address) .unwrap(); - assert_eq!(from_balance1, 200000); + assert_eq!(from_balance1, U256::from(200000u64)); let mut block_number = 0; let deploy_value = 0xfa; @@ -75,7 +75,7 @@ fn test_parse_log_event() { { assert_eq!(&the_from_addr, &address); assert_eq!(&the_to_addr, &contract_addr); - assert_eq!(amount, deploy_value); + assert_eq!(amount, U256::from(deploy_value)); } else { panic!("unexpected polyjuice log"); } @@ -142,7 +142,7 @@ fn test_parse_log_event() { assert_eq!(&the_from_addr, &address); // The block producer id is `0` assert_eq!(&the_to_addr, &block_producer); - assert_eq!(amount, 1814); + assert_eq!(amount, U256::from(1814u64)); } else { panic!("unexpected polyjuice log"); } diff --git a/polyjuice-tests/src/test_cases/recover_account.rs b/polyjuice-tests/src/test_cases/recover_account.rs index 83758c8c..5005c53f 100644 --- a/polyjuice-tests/src/test_cases/recover_account.rs +++ b/polyjuice-tests/src/test_cases/recover_account.rs @@ -26,7 +26,7 @@ fn test_recover_account() { let from_eth_address = [1u8; 20]; let (from_id, _from_script_hash) = - helper::create_eth_eoa_account(&mut state, &from_eth_address, 200000); + helper::create_eth_eoa_account(&mut state, &from_eth_address, 200000u64.into()); // Deploy RecoverAccount Contract let run_result = deploy( diff --git a/polyjuice-tests/src/test_cases/recursion_contract.rs b/polyjuice-tests/src/test_cases/recursion_contract.rs index 4297d706..da8dbcb9 100644 --- a/polyjuice-tests/src/test_cases/recursion_contract.rs +++ b/polyjuice-tests/src/test_cases/recursion_contract.rs @@ -20,7 +20,7 @@ fn test_recursion_contract_call() { let from_eth_address = [1u8; 20]; let (from_id, _from_script_hash) = - helper::create_eth_eoa_account(&mut state, &from_eth_address, 200000); + helper::create_eth_eoa_account(&mut state, &from_eth_address, 200000u64.into()); let mut block_number = 1; // Deploy RecursionContract diff --git a/polyjuice-tests/src/test_cases/selfdestruct.rs b/polyjuice-tests/src/test_cases/selfdestruct.rs index 2aee6adf..1aafa405 100644 --- a/polyjuice-tests/src/test_cases/selfdestruct.rs +++ b/polyjuice-tests/src/test_cases/selfdestruct.rs @@ -12,7 +12,7 @@ use gw_common::{ use gw_generator::traits::StateExt; use gw_store::chain_view::ChainView; use gw_store::traits::chain_store::ChainStore; -use gw_types::{bytes::Bytes, packed::RawL2Transaction, prelude::*}; +use gw_types::{bytes::Bytes, packed::RawL2Transaction, prelude::*, U256}; const INIT_CODE: &str = include_str!("./evm-contracts/SelfDestruct.bin"); @@ -23,19 +23,19 @@ fn test_selfdestruct() { let from_eth_address = [1u8; 20]; let (from_id, _from_script_hash) = - create_eth_eoa_account(&mut state, &from_eth_address, 200000); + create_eth_eoa_account(&mut state, &from_eth_address, 200000u64.into()); let beneficiary_eth_addr = [2u8; 20]; let beneficiary_ethabi_addr = eth_addr_to_ethabi_addr(&beneficiary_eth_addr); let (_beneficiary_id, _beneficiary_script_hash) = - create_eth_eoa_account(&mut state, &beneficiary_eth_addr, 0); + create_eth_eoa_account(&mut state, &beneficiary_eth_addr, 0u64.into()); let beneficiary_reg_addr = RegistryAddress::new(ETH_REGISTRY_ACCOUNT_ID, beneficiary_eth_addr.to_vec()); assert_eq!( state .get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &beneficiary_reg_addr) .unwrap(), - 0 + U256::zero() ); { @@ -87,13 +87,13 @@ fn test_selfdestruct() { state .get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &contract_reg_addr) .unwrap(), - 200 + U256::from(200) ); assert_eq!( state .get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &beneficiary_reg_addr) .unwrap(), - 0 + U256::zero() ); { // call SelfDestruct.done(); @@ -130,13 +130,13 @@ fn test_selfdestruct() { state .get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &contract_reg_addr) .unwrap(), - 0 + U256::zero() ); assert_eq!( state .get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &beneficiary_reg_addr) .unwrap(), - 200 + U256::from(200u64) ); { diff --git a/polyjuice-tests/src/test_cases/simple_storage.rs b/polyjuice-tests/src/test_cases/simple_storage.rs index 02f91a4d..0fe50927 100644 --- a/polyjuice-tests/src/test_cases/simple_storage.rs +++ b/polyjuice-tests/src/test_cases/simple_storage.rs @@ -21,7 +21,7 @@ fn test_simple_storage() { let from_eth_address = [1u8; 20]; let (from_id, _from_script_hash) = - helper::create_eth_eoa_account(&mut state, &from_eth_address, 200000); + helper::create_eth_eoa_account(&mut state, &from_eth_address, 200000u64.into()); let from_reg_addr = RegistryAddress::new(ETH_REGISTRY_ACCOUNT_ID, from_eth_address.to_vec()); let from_balance1 = state .get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &from_reg_addr) diff --git a/polyjuice-tests/src/test_cases/simple_transfer.rs b/polyjuice-tests/src/test_cases/simple_transfer.rs index 0a94ee3f..1b0c7935 100644 --- a/polyjuice-tests/src/test_cases/simple_transfer.rs +++ b/polyjuice-tests/src/test_cases/simple_transfer.rs @@ -12,7 +12,7 @@ use gw_common::{ use gw_generator::traits::StateExt; use gw_store::chain_view::ChainView; use gw_store::traits::chain_store::ChainStore; -use gw_types::{bytes::Bytes, packed::RawL2Transaction, prelude::*}; +use gw_types::{bytes::Bytes, packed::RawL2Transaction, prelude::*, U256}; use std::convert::TryInto; const SS_INIT_CODE: &str = include_str!("./evm-contracts/SimpleStorage.bin"); @@ -23,15 +23,15 @@ fn test_simple_transfer() { let (store, mut state, generator) = setup(); let block_producer_id = helper::create_block_producer(&mut state); - let mint_balance: u128 = 400000; + let mint_balance = U256::from(400000u128); let from_eth_address = [1u8; 20]; let (from_id, _from_script_hash) = - helper::create_eth_eoa_account(&mut state, &from_eth_address, mint_balance); + helper::create_eth_eoa_account(&mut state, &from_eth_address, mint_balance.into()); let from_addr = RegistryAddress::new(ETH_REGISTRY_ACCOUNT_ID, from_eth_address.to_vec()); let target_eth_addr = [2u8; 20]; let (target_id, _target_script_hash) = - helper::create_eth_eoa_account(&mut state, &target_eth_addr, 0); + helper::create_eth_eoa_account(&mut state, &target_eth_addr, 0u64.into()); let target_reg_addr = RegistryAddress::new(ETH_REGISTRY_ACCOUNT_ID, target_eth_addr.to_vec()); let from_balance = state @@ -41,7 +41,7 @@ fn test_simple_transfer() { let target_balance = state .get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &target_reg_addr) .unwrap(); - assert_eq!(target_balance, 0); + assert_eq!(target_balance, U256::zero()); // Deploy SimpleStorage let mut block_number = 0; @@ -79,7 +79,7 @@ fn test_simple_transfer() { let ss_balance = state .get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &ss_reg_addr) .unwrap(); - assert_eq!(ss_balance, 0); + assert_eq!(ss_balance, U256::zero()); let run_result = simple_storage_get( &store, &state, @@ -128,7 +128,7 @@ fn test_simple_transfer() { let st_contract_balance = state .get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &st_contract_reg_addr) .unwrap(); - assert_eq!(st_contract_balance, deploy_value); + assert_eq!(st_contract_balance, U256::from(deploy_value)); println!("================"); println!( @@ -178,11 +178,11 @@ fn test_simple_transfer() { let new_balance = state .get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &st_contract_reg_addr) .unwrap(); - assert_eq!(new_balance, old_balance - 1); + assert_eq!(new_balance, old_balance - 1u64); let target_balance = state .get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &target_reg_addr) .unwrap(); - assert_eq!(target_balance, 1); + assert_eq!(target_balance, U256::one()); } // TODO: check this logic: can't transfer to zero_address{0} @@ -285,11 +285,11 @@ fn test_simple_transfer() { let new_balance = state .get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &st_contract_reg_addr) .unwrap(); - assert_eq!(new_balance, old_balance - 1); + assert_eq!(new_balance, old_balance - 1u64); let ss_balance = state .get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &ss_reg_addr) .unwrap(); - assert_eq!(ss_balance, 1); + assert_eq!(ss_balance, U256::one()); println!("================"); let run_result = simple_storage_get( &store, @@ -344,11 +344,11 @@ fn test_simple_transfer() { let new_balance = state .get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &st_contract_reg_addr) .unwrap(); - assert_eq!(new_balance, old_balance - 1); + assert_eq!(new_balance, old_balance - 1u64); let ss_balance = state .get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &ss_reg_addr) .unwrap(); - assert_eq!(ss_balance, 2); + assert_eq!(ss_balance, U256::from(2u64)); let run_result = simple_storage_get( &store, &state, diff --git a/polyjuice-tests/src/test_cases/simple_wallet.rs b/polyjuice-tests/src/test_cases/simple_wallet.rs index 55167fef..701139cc 100644 --- a/polyjuice-tests/src/test_cases/simple_wallet.rs +++ b/polyjuice-tests/src/test_cases/simple_wallet.rs @@ -13,7 +13,7 @@ fn test_simple_wallet() { let from_eth_address = [1u8; 20]; let (from_id, _from_script_hash) = - helper::create_eth_eoa_account(&mut state, &from_eth_address, 20000000); + helper::create_eth_eoa_account(&mut state, &from_eth_address, 20000000u64.into()); // Deploy SimpleWallet Contract let block_number = 1; diff --git a/polyjuice-tests/src/test_cases/sudt_erc20_proxy.rs b/polyjuice-tests/src/test_cases/sudt_erc20_proxy.rs index 08ffbe21..ec6c53d4 100644 --- a/polyjuice-tests/src/test_cases/sudt_erc20_proxy.rs +++ b/polyjuice-tests/src/test_cases/sudt_erc20_proxy.rs @@ -13,7 +13,7 @@ use gw_common::state::State; use gw_generator::{dummy_state::DummyState, error::TransactionError, traits::StateExt, Generator}; use gw_store::traits::chain_store::ChainStore; use gw_store::{chain_view::ChainView, Store}; -use gw_types::{bytes::Bytes, packed::RawL2Transaction, prelude::*}; +use gw_types::{bytes::Bytes, packed::RawL2Transaction, prelude::*, U256}; fn test_sudt_erc20_proxy_inner( generator: &Generator, @@ -27,17 +27,17 @@ fn test_sudt_erc20_proxy_inner( let from_eth_address1 = [1u8; 20]; let (from_id1, _from_script_hash1) = - helper::create_eth_eoa_account(state, &from_eth_address1, 2000000); + helper::create_eth_eoa_account(state, &from_eth_address1, 2000000u64.into()); let from_reg_addr1 = RegistryAddress::new(ETH_REGISTRY_ACCOUNT_ID, from_eth_address1.to_vec()); let from_eth_address2 = [2u8; 20]; let (_from_id2, _from_script_hash2) = - helper::create_eth_eoa_account(state, &from_eth_address2, 2000000); + helper::create_eth_eoa_account(state, &from_eth_address2, 2000000u64.into()); let from_reg_addr2 = RegistryAddress::new(ETH_REGISTRY_ACCOUNT_ID, from_eth_address2.to_vec()); let from_eth_address3 = [3u8; 20]; let (from_id3, _from_script_hash3) = - helper::create_eth_eoa_account(state, &from_eth_address3, 2000000); + helper::create_eth_eoa_account(state, &from_eth_address3, 2000000u64.into()); let from_reg_addr3 = RegistryAddress::new(ETH_REGISTRY_ACCOUNT_ID, from_eth_address3.to_vec()); // Deploy SudtERC20Proxy_UserDefinedDecimals @@ -77,7 +77,7 @@ fn test_sudt_erc20_proxy_inner( .mint_sudt( new_sudt_id, &from_reg_addr1, - 160000000000000000000000000000u128, + U256::from(160000000000000000000000000000u128), ) .unwrap(); @@ -85,19 +85,19 @@ fn test_sudt_erc20_proxy_inner( state .get_sudt_balance(new_sudt_id, &from_reg_addr1) .unwrap(), - 160000000000000000000000000000u128 + U256::from(160000000000000000000000000000u128) ); assert_eq!( state .get_sudt_balance(new_sudt_id, &from_reg_addr2) .unwrap(), - 0 + U256::zero() ); assert_eq!( state .get_sudt_balance(new_sudt_id, &from_reg_addr3) .unwrap(), - 0 + U256::zero() ); let total_supply = {