mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-04-26 02:57:57 +00:00
@@ -154,6 +154,12 @@ sol!(
|
||||
}
|
||||
);
|
||||
|
||||
sol!(
|
||||
contract Bitwise {
|
||||
function opByte(uint i, uint x) public payable returns (uint ret);
|
||||
}
|
||||
);
|
||||
|
||||
impl Contract {
|
||||
/// Execute the contract.
|
||||
///
|
||||
@@ -508,6 +514,18 @@ impl Contract {
|
||||
calldata: Value::balance_ofCall::new((address,)).abi_encode(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bitwise_byte(index: U256, value: U256) -> Self {
|
||||
let code = include_str!("../contracts/Bitwise.sol");
|
||||
let name = "Bitwise";
|
||||
|
||||
Self {
|
||||
name,
|
||||
evm_runtime: crate::compile_evm_bin_runtime(name, code),
|
||||
pvm_runtime: crate::compile_blob(name, code),
|
||||
calldata: Bitwise::opByteCall::new((index, value)).abi_encode(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use alloy_primitives::{keccak256, Address, FixedBytes, B256, I256, U256};
|
||||
use alloy_sol_types::{sol, SolCall, SolValue};
|
||||
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
|
||||
@@ -590,3 +592,25 @@ fn balance() {
|
||||
let received = U256::from_be_slice(&output.data);
|
||||
assert_eq!(expected, received)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bitwise_byte() {
|
||||
assert_success(&Contract::bitwise_byte(U256::ZERO, U256::ZERO), true);
|
||||
assert_success(&Contract::bitwise_byte(U256::ZERO, U256::MAX), true);
|
||||
assert_success(&Contract::bitwise_byte(U256::MAX, U256::ZERO), true);
|
||||
assert_success(
|
||||
&Contract::bitwise_byte(U256::from_str("18446744073709551619").unwrap(), U256::MAX),
|
||||
true,
|
||||
);
|
||||
|
||||
let de_bruijn_sequence =
|
||||
hex::decode("4060503824160d0784426150b864361d0f88c4a27148ac5a2f198d46e391d8f4").unwrap();
|
||||
let value = U256::from_be_bytes::<32>(de_bruijn_sequence.clone().try_into().unwrap());
|
||||
|
||||
for (index, byte) in de_bruijn_sequence.iter().enumerate() {
|
||||
let (_, output) = assert_success(&Contract::bitwise_byte(U256::from(index), value), true);
|
||||
let expected = U256::from(*byte as i32);
|
||||
let received = U256::abi_decode(&output.data, true).unwrap();
|
||||
assert_eq!(expected, received)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user