Skip to content

Commit ad0f058

Browse files
authored
feat: add contracts to test utils and signet test evm (#111)
1 parent d0d37c4 commit ad0f058

File tree

10 files changed

+150
-3
lines changed

10 files changed

+150
-3
lines changed

crates/bundle/src/send/bundle.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ impl SignetEthBundle {
110110

111111
/// Check that this fill is valid on-chain as of the current block. This
112112
/// checks that the tokens can actually be transferred.
113+
///
114+
/// # WARNING:
115+
///
116+
/// This function will send an RPC request to the provider containing the
117+
/// fills. It MUST NOT be used with an untrusted provider.
113118
pub async fn alloy_validate_fills_onchain<Db, P, N>(
114119
&self,
115120
orders: HostOrdersInstance<P, N>,
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use alloy::{
2+
primitives::{b256, bytes, Address, Bytes, B256},
3+
providers::Provider,
4+
};
5+
6+
alloy::sol! {
7+
#[sol(rpc)]
8+
#[derive(Debug)]
9+
contract Counter {
10+
uint256 public count;
11+
event Count(uint256 indexed count);
12+
function increment() public;
13+
14+
}
15+
}
16+
17+
/// A test address for the Counter.sol contract, which will be pre-deployed in
18+
/// test EVMs.
19+
pub const COUNTER_TEST_ADDRESS: Address = Address::repeat_byte(0x49);
20+
21+
/// Calculated bytecode hash for the Counter.sol contract. Keccak256[`COUNTER_BYTECODE`].
22+
pub const COUNTER_BYTECODE_HASH: B256 =
23+
b256!("0x905f7a46c9105d8c0d5d6368b601da50e09cdd1fffa5ed6b6548ed6a15bf3a6b");
24+
25+
/// Deploycode for the Counter.sol contract. Sending a transaction with this
26+
/// code will deploy the contract, and the account will then contain
27+
/// [`COUNTER_BYTECODE`].
28+
///
29+
/// Generated from:
30+
/// solc --optimize --via-ir --bin crates/test-utils/tests/artifacts/Counter.sol
31+
pub const COUNTER_DEPLOY_CODE: Bytes = bytes!(
32+
"608080604052346016575f805560d79081601b8239f35b5f80fdfe60808060405260043610156011575f80fd5b5f3560e01c90816306661abd14608a575063d09de08a14602f575f80fd5b346086575f3660031901126086575f5460018101809111607257805f557face32e4392fafee7f8245a5ae6a32722dc74442d018c52e460835648cbeeeba15f80a2005b634e487b7160e01b5f52601160045260245ffd5b5f80fd5b346086575f3660031901126086576020905f548152f3fea264697066735822122027a064635c397ba96bfe6d499e93133378e80d56d94510a0ffa4a51969bcf09464736f6c634300081a0033"
33+
);
34+
35+
/// Post-deployment bytecode for the Counter.sol contract.
36+
pub const COUNTER_BYTECODE: Bytes = bytes!(
37+
"60808060405260043610156011575f80fd5b5f3560e01c90816306661abd14608a575063d09de08a14602f575f80fd5b346086575f3660031901126086575f5460018101809111607257805f557face32e4392fafee7f8245a5ae6a32722dc74442d018c52e460835648cbeeeba15f80a2005b634e487b7160e01b5f52601160045260245ffd5b5f80fd5b346086575f3660031901126086576020905f548152f3fea264697066735822122027a064635c397ba96bfe6d499e93133378e80d56d94510a0ffa4a51969bcf09464736f6c634300081a0033"
38+
);
39+
40+
/// Get an instance of the pre-deployed Counter contract.
41+
pub fn counter<P: Provider>(p: P) -> Counter::CounterInstance<P> {
42+
Counter::CounterInstance::new(COUNTER_TEST_ADDRESS, p)
43+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub mod counter;
2+
3+
pub mod system;
4+
5+
pub mod token;

crates/test-utils/src/contracts/system.rs

Lines changed: 22 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use alloy::{
2+
primitives::{bytes, Bytes, U256},
3+
uint,
4+
};
5+
6+
/// Slot at which the token name is stored.
7+
pub const NAME_SLOT: U256 = uint!(3_U256);
8+
/// Slot at which the token symbol is stored.
9+
pub const SYMBOL_SLOT: U256 = uint!(4_U256);
10+
/// Slot at which the token minter is stored.
11+
pub const MINTER_SLOT: U256 = uint!(5_U256);
12+
13+
/// Address of the token minter.
14+
pub const MINTER: U256 =
15+
uint!(0x00000000000000000000000000000000000000000000746f6b656e61646d696e_U256);
16+
/// WBTC Contract name.
17+
pub const WBTC_NAME: U256 =
18+
uint!(0x5772617070656420425443000000000000000000000000000000000000000016_U256);
19+
/// WBTC Contract symbol.
20+
pub const WBTC_SYMBOL: U256 =
21+
uint!(0x5742544300000000000000000000000000000000000000000000000000000008_U256);
22+
/// WETH Contract name.
23+
pub const WETH_NAME: U256 =
24+
uint!(0x577261707065642045746865720000000000000000000000000000000000001a_U256);
25+
/// WETH Contract symbol.
26+
pub const WETH_SYMBOL: U256 =
27+
uint!(0x5745544800000000000000000000000000000000000000000000000000000008_U256);
28+
29+
/// Token Contract bytecode, from pecorino genesis.
30+
pub const TOKEN_BYTECODE: Bytes = bytes!("0x608060405234801561000f575f80fd5b50600436106100fb575f3560e01c806370a082311161009357806395d89b411161006357806395d89b4114610246578063a9059cbb1461024e578063dd62ed3e14610261578063f2fde38b14610299575f80fd5b806370a08231146101e8578063715018a61461021057806379cc6790146102185780638da5cb5b1461022b575f80fd5b8063313ce567116100ce578063313ce5671461016557806332424aa31461019957806340c10f19146101c057806342966c68146101d3575f80fd5b806306fdde03146100ff578063095ea7b31461011d57806318160ddd1461014057806323b872dd14610152575b5f80fd5b6101076102ac565b60405161011491906107f0565b60405180910390f35b61013061012b366004610840565b61033c565b6040519015158152602001610114565b6002545b604051908152602001610114565b610130610160366004610868565b610355565b7f00000000000000000000000000000000000000000000000000000000000000085b60405160ff9091168152602001610114565b6101877f000000000000000000000000000000000000000000000000000000000000000881565b6101306101ce366004610840565b610378565b6101e66101e13660046108a2565b610394565b005b6101446101f63660046108b9565b6001600160a01b03165f9081526020819052604090205490565b6101e66103a1565b6101e6610226366004610840565b6103b4565b6005546040516001600160a01b039091168152602001610114565b6101076103cd565b61013061025c366004610840565b6103dc565b61014461026f3660046108d9565b6001600160a01b039182165f90815260016020908152604080832093909416825291909152205490565b6101e66102a73660046108b9565b6103e9565b6060600380546102bb9061090a565b80601f01602080910402602001604051908101604052809291908181526020018280546102e79061090a565b80156103325780601f1061030957610100808354040283529160200191610332565b820191905f5260205f20905b81548152906001019060200180831161031557829003601f168201915b5050505050905090565b5f33610349818585610428565b60019150505b92915050565b5f3361036285828561043a565b61036d8585856104b5565b506001949350505050565b5f610381610512565b61038b838361053f565b50600192915050565b61039e3382610573565b50565b6103a9610512565b6103b25f6105a7565b565b6103bf82338361043a565b6103c98282610573565b5050565b6060600480546102bb9061090a565b5f336103498185856104b5565b6103f1610512565b6001600160a01b03811661041f57604051631e4fbdf760e01b81525f60048201526024015b60405180910390fd5b61039e816105a7565b61043583838360016105f8565b505050565b6001600160a01b038381165f908152600160209081526040808320938616835292905220545f1981146104af57818110156104a157604051637dc7a0d960e11b81526001600160a01b03841660048201526024810182905260448101839052606401610416565b6104af84848484035f6105f8565b50505050565b6001600160a01b0383166104de57604051634b637e8f60e11b81525f6004820152602401610416565b6001600160a01b0382166105075760405163ec442f0560e01b81525f6004820152602401610416565b6104358383836106ca565b6005546001600160a01b031633146103b25760405163118cdaa760e01b8152336004820152602401610416565b6001600160a01b0382166105685760405163ec442f0560e01b81525f6004820152602401610416565b6103c95f83836106ca565b6001600160a01b03821661059c57604051634b637e8f60e11b81525f6004820152602401610416565b6103c9825f836106ca565b600580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a35050565b6001600160a01b0384166106215760405163e602df0560e01b81525f6004820152602401610416565b6001600160a01b03831661064a57604051634a1406b160e11b81525f6004820152602401610416565b6001600160a01b038085165f90815260016020908152604080832093871683529290522082905580156104af57826001600160a01b0316846001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040516106bc91815260200190565b60405180910390a350505050565b6001600160a01b0383166106f4578060025f8282546106e99190610942565b909155506107649050565b6001600160a01b0383165f90815260208190526040902054818110156107465760405163391434e360e21b81526001600160a01b03851660048201526024810182905260448101839052606401610416565b6001600160a01b0384165f9081526020819052604090209082900390555b6001600160a01b0382166107805760028054829003905561079e565b6001600160a01b0382165f9081526020819052604090208054820190555b816001600160a01b0316836001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040516107e391815260200190565b60405180910390a3505050565b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f83011684010191505092915050565b80356001600160a01b038116811461083b575f80fd5b919050565b5f8060408385031215610851575f80fd5b61085a83610825565b946020939093013593505050565b5f805f6060848603121561087a575f80fd5b61088384610825565b925061089160208501610825565b929592945050506040919091013590565b5f602082840312156108b2575f80fd5b5035919050565b5f602082840312156108c9575f80fd5b6108d282610825565b9392505050565b5f80604083850312156108ea575f80fd5b6108f383610825565b915061090160208401610825565b90509250929050565b600181811c9082168061091e57607f821691505b60208210810361093c57634e487b7160e01b5f52602260045260245ffd5b50919050565b8082018082111561034f57634e487b7160e01b5f52601160045260245ffdfea2646970667358221220a373554eb2e797644d86447291ab79350d58226b5edc56a67e2d820f602062bb64736f6c634300081a0033");

crates/test-utils/src/evm.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,43 @@
11
use signet_constants::test_utils::*;
22
use trevm::revm::{
33
context::CfgEnv, database::in_memory_db::InMemoryDB, primitives::hardfork::SpecId,
4+
state::Bytecode,
45
};
56

6-
/// Create a new Signet EVM with an in-memory database for testing.
7+
use crate::contracts::{
8+
counter::{COUNTER_BYTECODE, COUNTER_TEST_ADDRESS},
9+
system::{RU_ORDERS_BYTECODE, RU_PASSAGE_BYTECODE},
10+
token::{
11+
MINTER, MINTER_SLOT, NAME_SLOT, SYMBOL_SLOT, TOKEN_BYTECODE, WBTC_NAME, WBTC_SYMBOL,
12+
WETH_NAME, WETH_SYMBOL,
13+
},
14+
};
15+
16+
/// Create a new Signet EVM with an in-memory database for testing. Deploy
17+
/// system contracts and pre-deployed tokens.
718
pub fn test_signet_evm() -> signet_evm::EvmNeedsBlock<InMemoryDB> {
8-
signet_evm::signet_evm(InMemoryDB::default(), TEST_SYS).fill_cfg(&TestCfg)
19+
let mut evm = signet_evm::signet_evm(InMemoryDB::default(), TEST_SYS).fill_cfg(&TestCfg);
20+
21+
// Set the bytecode for system contracts
22+
evm.set_bytecode_unchecked(TEST_SYS.ru_orders(), Bytecode::new_legacy(RU_ORDERS_BYTECODE));
23+
evm.set_bytecode_unchecked(TEST_SYS.ru_passage(), Bytecode::new_legacy(RU_PASSAGE_BYTECODE));
24+
25+
// Set WBTC bytecode and storage
26+
evm.set_bytecode_unchecked(RU_WBTC, Bytecode::new_legacy(TOKEN_BYTECODE));
27+
evm.set_storage_unchecked(RU_WBTC, NAME_SLOT, WBTC_NAME);
28+
evm.set_storage_unchecked(RU_WBTC, SYMBOL_SLOT, WBTC_SYMBOL);
29+
evm.set_storage_unchecked(RU_WBTC, MINTER_SLOT, MINTER);
30+
31+
// Set WETH bytecode and storage
32+
evm.set_bytecode_unchecked(RU_WETH, Bytecode::new_legacy(TOKEN_BYTECODE));
33+
evm.set_storage_unchecked(RU_WETH, NAME_SLOT, WETH_NAME);
34+
evm.set_storage_unchecked(RU_WETH, SYMBOL_SLOT, WETH_SYMBOL);
35+
evm.set_storage_unchecked(RU_WETH, MINTER_SLOT, MINTER);
36+
37+
// Set the bytecode for the Counter contract
38+
evm.set_bytecode_unchecked(COUNTER_TEST_ADDRESS, Bytecode::new_legacy(COUNTER_BYTECODE));
39+
40+
evm
941
}
1042

1143
/// Test configuration for the Signet EVM.

crates/test-utils/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub mod chain;
2+
pub mod contracts;
23
pub mod evm;
34
pub mod specs;
45
pub mod users;

crates/test-utils/tests/bundle.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//! Tests for the bundle guarantees.
2+
//!
3+
//! - Txns must not revert, unless marked as revertible.
4+
//! - Txns must not be dropped by market rules, unless marked as droppable.
5+
6+
#[tokio::test]
7+
async fn test_bundle_guarantees() {}

crates/test-utils/tests/evm.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ fn test_an_enter() {
209209
assert_eq!(sealed_block.senders.len(), 1);
210210
assert_eq!(sealed_block.block.body.transactions().collect::<Vec<_>>(), vec![&expected_tx]);
211211
assert_eq!(receipts.len(), 1);
212+
dbg!(&receipts);
212213

213214
let ReceiptEnvelope::Eip1559(ref receipt) = receipts[0] else {
214215
panic!("expected 1559 receipt")

crates/types/src/signing/fill.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ impl SignedFill {
5353
///
5454
/// For it to be valid:
5555
/// - Deadline must be in the future.
56-
/// - The permits must exactly match the ordering, token, and amount of the outputs.
56+
/// - The permits must exactly match the ordering, token, and amount of the
57+
/// outputs.
5758
pub fn validate(&self, timestamp: u64) -> Result<(), SignedPermitError> {
5859
let deadline = self.permit.permit.deadline.saturating_to::<u64>();
5960
if timestamp > deadline {

0 commit comments

Comments
 (0)