Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroqn committed Apr 28, 2022
1 parent f25f3cb commit 7c6d951
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 71 deletions.
8 changes: 4 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ const CKB_HASH_PERSONALIZATION: &[u8] = b"ckb-default-hash";
const BINARIES: &[(&str, &str)] = &[
(
"generator",
"2dedb79afb0bffb21e01a832866cb32bd49bbde0af4b76e3c1fe8d7e1943cf52",
"1b542a36f901ceb3e92fd9d61f7bcab734dd6d705e0d1a001eef00066cf2cfcb",
),
(
"validator",
"30e56ee291fd106f752253654966e6789bf247d73ae731df5650361f26eb36cf",
"de556767bceef4e82f07850575ad8ddce86917e8d74c0b4043089faf209e945f",
),
(
"generator_log",
"a9ea7e5940b0c2cf21dd8a07bd9bce20aca3edc007ffb70a19f50ed6f4e9c418",
"57674c55e4d9d3a3d3770fb78083d60abdfde58fead63ee7a496bdfe2b0e78e1",
),
(
"validator_log",
"3998335dc17c056512e51c8ad1e08ed147e54eb6fb78372b8203cda40c573bb3",
"2026d63802cf57bc5c4b1cba6b404792bdeead572f7ce175c1bb9a370ef06dc8",
),
];

Expand Down
2 changes: 1 addition & 1 deletion c/polyjuice_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,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/uint64_t/uint128_t/uint256_t from big endian byte32 data */
/* Parse uint32_t/uint64_t/uint128_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) {
Expand Down
2 changes: 1 addition & 1 deletion devtools/ci/integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ else
fi
cd $GODWOKEN_DIR
# checkout https://github.com/nervosnetwork/godwoken/pull/659/head
git fetch origin ed9d3ab716ea5d5a8f22f5ea7e6c90e23b6a49a8
git fetch origin 8a8e0b7cd038fab41d44e6e4b936276d22c21171
git checkout FETCH_HEAD
git submodule update --init --recursive --depth=1

Expand Down
23 changes: 11 additions & 12 deletions polyjuice-tests/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use gw_types::{
Script, SetMapping, Uint64,
},
prelude::*,
U256,
};
use gw_types::{
offchain::RollupContext,
Expand Down Expand Up @@ -127,13 +126,13 @@ pub enum Log {
sudt_id: u32,
from_addr: RegistryAddress,
to_addr: RegistryAddress,
amount: U256,
amount: u128,
},
SudtPayFee {
sudt_id: u32,
from_addr: RegistryAddress,
block_producer_addr: RegistryAddress,
amount: U256,
amount: u128,
},
PolyjuiceSystem {
gas_used: u64,
Expand All @@ -148,13 +147,13 @@ pub enum Log {
},
}

fn parse_sudt_log_data(data: &[u8]) -> (RegistryAddress, RegistryAddress, U256) {
fn parse_sudt_log_data(data: &[u8]) -> (RegistryAddress, RegistryAddress, u128) {
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 u256_bytes = [0u8; 32];
u256_bytes.copy_from_slice(&data[56..56 + 32]);
let amount = U256::from_little_endian(&mut u256_bytes);
let mut u128_bytes = [0u8; 16];
u128_bytes.copy_from_slice(&data[56..56 + 16]);
let amount = u128::from_le_bytes(u128_bytes);
(from_addr, to_addr, amount)
}

Expand All @@ -165,7 +164,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 + 32) {
if data.len() != (28 + 28 + 16) {
panic!("Invalid data length: {}", data.len());
}
let (from_addr, to_addr, amount) = parse_sudt_log_data(data);
Expand All @@ -178,7 +177,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 + 32) {
if data.len() != (28 + 28 + 16) {
panic!("Invalid data length: {}", data.len());
}
let (from_addr, block_producer_addr, amount) = parse_sudt_log_data(data);
Expand Down Expand Up @@ -686,7 +685,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: impl Into<U256>,
mint_ckb: u128,
) -> (u32, [u8; 32]) {
let script = build_eth_l2_script(eth_address);
let script_hash = script.hash();
Expand Down Expand Up @@ -755,7 +754,7 @@ pub(crate) fn eth_address_regiser(
SetMappingArgs::One(gw_script_hash) => {
let fee = Fee::new_builder()
.registry_id(ETH_REGISTRY_ACCOUNT_ID.pack())
.amount(U256::from(1000u64).pack())
.amount(1000u128.pack())
.build();
let set_mapping = SetMapping::new_builder()
.fee(fee)
Expand All @@ -769,7 +768,7 @@ pub(crate) fn eth_address_regiser(
SetMappingArgs::Batch(gw_script_hashes) => {
let fee = Fee::new_builder()
.registry_id(ETH_REGISTRY_ACCOUNT_ID.pack())
.amount(U256::from(1000u64).pack())
.amount(1000u128.pack())
.build();
let batch_set_mapping = BatchSetMapping::new_builder()
.fee(fee)
Expand Down
12 changes: 6 additions & 6 deletions polyjuice-tests/src/test_cases/call_selfdestruct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*, U256};
use gw_types::{bytes::Bytes, packed::RawL2Transaction, prelude::*};

const SD_INIT_CODE: &str = include_str!("./evm-contracts/SelfDestruct.bin");
const CALL_SD_INIT_CODE: &str = include_str!("./evm-contracts/CallSelfDestruct.bin");
Expand All @@ -33,7 +33,7 @@ fn test_selfdestruct() {
state
.get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &beneficiary_address)
.unwrap(),
U256::zero()
0
);

// deploy SelfDestruct
Expand Down Expand Up @@ -71,13 +71,13 @@ fn test_selfdestruct() {
state
.get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &sd_address)
.unwrap(),
U256::from(200u64)
200
);
assert_eq!(
state
.get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &beneficiary_address)
.unwrap(),
U256::zero()
0
);

// deploy CallSelfDestruct
Expand Down Expand Up @@ -152,13 +152,13 @@ fn test_selfdestruct() {
state
.get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &sd_address)
.unwrap(),
U256::zero()
0
);
assert_eq!(
state
.get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &beneficiary_address)
.unwrap(),
U256::from(200u64)
200
);

block_number += 1;
Expand Down
6 changes: 3 additions & 3 deletions polyjuice-tests/src/test_cases/create2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*, U256};
use gw_types::{bytes::Bytes, packed::RawL2Transaction, prelude::*};

const SS_INIT_CODE: &str = include_str!("./evm-contracts/SimpleStorage.bin");
const CREATE2_IMPL_CODE: &str = include_str!("./evm-contracts/Create2Impl.bin");
Expand Down Expand Up @@ -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, U256::zero());
assert_eq!(create2_contract_balance, 0);

let input_value_u128: u128 = 0x9a;
// bytes32 salt
Expand Down Expand Up @@ -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, U256::from(input_value_u128));
assert_eq!(create2_account_balance, input_value_u128);

let run_result = simple_storage_get(
&store,
Expand Down
16 changes: 8 additions & 8 deletions polyjuice-tests/src/test_cases/eth_addr_reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*, U256};
use gw_types::{packed::RawL2Transaction, prelude::*};

const SS_INIT_CODE: &str = include_str!("./evm-contracts/SimpleStorage.bin");

Expand Down Expand Up @@ -79,7 +79,7 @@ fn test_update_eth_addr_reg_by_contract() {
state
.get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &address)
.unwrap(),
U256::zero()
0u128
);
state /* mint CKB to pay fee */
.mint_sudt(CKB_SUDT_ACCOUNT_ID, &address, 52000)
Expand All @@ -88,7 +88,7 @@ fn test_update_eth_addr_reg_by_contract() {
state
.get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &address)
.unwrap(),
U256::from(52000u128)
52000u128
);

// update_eth_address_registry by `ETH Address Registry` layer2 contract
Expand All @@ -110,7 +110,7 @@ fn test_update_eth_addr_reg_by_contract() {
state
.get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &address)
.unwrap(),
U256::from(51000u128)
51000u128
);

// try to register the same account again
Expand Down Expand Up @@ -203,7 +203,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, 400000u64);
helper::create_eth_eoa_account(&mut state, &from_eth_address, 400000);

// create new EOAs which is not registered
let eth_eoa_addresses = vec![[0xeeu8; 20], [0xefu8; 20]];
Expand All @@ -219,16 +219,16 @@ fn test_batch_set_mapping_by_contract() {
state
.get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &address)
.unwrap(),
U256::zero()
0u128
);
state /* mint CKB to pay fee */
.mint_sudt(CKB_SUDT_ACCOUNT_ID, &address, 200000u64)
.mint_sudt(CKB_SUDT_ACCOUNT_ID, &address, 200000)
.unwrap();
assert_eq!(
state
.get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &address)
.unwrap(),
U256::from(200000u128)
200000u128
);
}

Expand Down
14 changes: 4 additions & 10 deletions polyjuice-tests/src/test_cases/invalid_sudt_erc20_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*, U256};
use gw_types::{bytes::Bytes, packed::RawL2Transaction, prelude::*};

const INVALID_SUDT_ERC20_PROXY_CODE: &str =
include_str!("./evm-contracts/InvalidSudtERC20Proxy.bin");
Expand Down Expand Up @@ -82,16 +82,10 @@ fn test_invalid_sudt_erc20_proxy() {

assert_eq!(
state.get_sudt_balance(new_sudt_id, &address1).unwrap(),
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()
160000000000000000000000000000u128
);
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)
(
Expand Down
8 changes: 4 additions & 4 deletions polyjuice-tests/src/test_cases/parse_log_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*, U256};
use gw_types::{bytes::Bytes, packed::RawL2Transaction, prelude::*};

const INIT_CODE: &str = include_str!("./evm-contracts/LogEvents.bin");

Expand All @@ -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, U256::from(200000u64));
assert_eq!(from_balance1, 200000);

let mut block_number = 0;
let deploy_value = 0xfa;
Expand Down Expand Up @@ -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, U256::from(deploy_value));
assert_eq!(amount, deploy_value);
} else {
panic!("unexpected polyjuice log");
}
Expand Down Expand Up @@ -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, U256::from(1814u64));
assert_eq!(amount, 1814);
} else {
panic!("unexpected polyjuice log");
}
Expand Down
12 changes: 6 additions & 6 deletions polyjuice-tests/src/test_cases/selfdestruct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*, U256};
use gw_types::{bytes::Bytes, packed::RawL2Transaction, prelude::*};

const INIT_CODE: &str = include_str!("./evm-contracts/SelfDestruct.bin");

Expand All @@ -35,7 +35,7 @@ fn test_selfdestruct() {
state
.get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &beneficiary_reg_addr)
.unwrap(),
U256::zero()
0
);

{
Expand Down Expand Up @@ -87,13 +87,13 @@ fn test_selfdestruct() {
state
.get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &contract_reg_addr)
.unwrap(),
U256::from(200)
200
);
assert_eq!(
state
.get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &beneficiary_reg_addr)
.unwrap(),
U256::zero()
0
);
{
// call SelfDestruct.done();
Expand Down Expand Up @@ -130,13 +130,13 @@ fn test_selfdestruct() {
state
.get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &contract_reg_addr)
.unwrap(),
U256::zero()
0
);
assert_eq!(
state
.get_sudt_balance(CKB_SUDT_ACCOUNT_ID, &beneficiary_reg_addr)
.unwrap(),
U256::from(200u64)
200
);

{
Expand Down
Loading

0 comments on commit 7c6d951

Please sign in to comment.