Skip to content

Commit

Permalink
add test to read EVM contract from ReadBuf
Browse files Browse the repository at this point in the history
  • Loading branch information
saibatizoku committed Oct 12, 2021
1 parent 0c404b3 commit 3bb3d18
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions chain-impl-mockchain/src/smartcontract/mod.rs
Expand Up @@ -55,3 +55,56 @@ impl Payload for Contract {
todo!();
}
}

#[cfg(test)]
mod tests {
use super::*;
use typed_bytes::ByteBuilder;

#[cfg(feature = "evm")]
#[test]
fn test_readable_evm_contract() {
use chain_core::mempack::ReadBuf;
use typed_bytes::ByteArray;

let from = AccountAddress::random();
let to = None;
let gas: Gas = 10000.into();
let gas_price: GasPrice = 2000.into();
let value = None;
let data = None;

let contract_type = 0; // Contract::EVM = 0
let has_to = 0;
let has_gas = 1;
let has_gas_price = 1;
let has_value = 0;
let has_data = 0;

let bb: ByteArray<Contract> = ByteBuilder::new()
.u8(contract_type)
.bytes(from.as_fixed_bytes())
.u8(has_to)
.u8(has_gas)
.bytes(&<[u8; 32]>::from(gas))
.u8(has_gas_price)
.bytes(&<[u8; 32]>::from(gas_price))
.u8(has_value)
.u8(has_data)
.finalize();

let mut readbuf = ReadBuf::from(bb.as_slice());
let contract = Contract::read(&mut readbuf).unwrap();

let expected = Contract::EVM {
from,
to,
gas: Some(gas),
gas_price: Some(gas_price),
value,
data,
};

assert_eq!(contract, expected);
}
}

0 comments on commit 3bb3d18

Please sign in to comment.