Skip to content

Commit 2ce9611

Browse files
jmg-duartesquadgazzz
authored andcommitted
Migrate Counter into alloy (cowprotocol#3762)
# Description Migrate Counter into alloy # Changes <!-- List of detailed changes (how the change is accomplished) --> - [ ] Remove old bindings - [ ] Add new bindings - [ ] Adapt tests ## How to test Tests <!-- ## Related Issues Fixes # --> --------- Co-authored-by: ilya <ilya@cow.fi>
1 parent 2f27e6e commit 2ce9611

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

crates/contracts/build.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,9 +1027,6 @@ fn main() {
10271027
.add_network_str(SEPOLIA, "0x3e8C6De9510e7ECad902D005DE3Ab52f35cF4f1b")
10281028
});
10291029

1030-
// Test Contract for incrementing arbitrary counters.
1031-
generate_contract("Counter");
1032-
10331030
// Contract for Uniswap's Permit2 contract.
10341031
generate_contract_with_config("Permit2", |builder| {
10351032
builder

crates/contracts/src/alloy.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,8 @@ pub mod support {
616616
pub mod test {
617617
// Test Contract for using up a specified amount of gas.
618618
crate::bindings!(GasHog);
619+
// Test Contract for incrementing arbitrary counters.
620+
crate::bindings!(Counter);
619621
}
620622

621623
pub use alloy::providers::DynProvider as Provider;

crates/contracts/src/lib.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,6 @@ pub mod support {
9494
}
9595
}
9696

97-
pub mod test {
98-
include_contracts! {
99-
Counter;
100-
}
101-
}
102-
10397
#[cfg(test)]
10498
mod tests {
10599
use crate::alloy::networks::{

crates/e2e/tests/e2e/hooks.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,7 @@ async fn partial_fills(web3: Web3) {
428428
let [solver] = onchain.make_solvers(to_wei(1)).await;
429429
let [trader] = onchain.make_accounts(to_wei(3)).await;
430430

431-
let counter = contracts::test::Counter::builder(&web3)
432-
.deploy()
431+
let counter = contracts::alloy::test::Counter::Instance::deploy(web3.alloy.clone())
433432
.await
434433
.unwrap();
435434

@@ -454,6 +453,20 @@ async fn partial_fills(web3: Web3) {
454453
let services = Services::new(&onchain).await;
455454
services.start_protocol(solver).await;
456455

456+
let pre_inc = counter.incrementCounter("pre".to_string());
457+
let pre_hook = Hook {
458+
target: counter.address().into_legacy(),
459+
call_data: pre_inc.calldata().to_vec(),
460+
gas_limit: pre_inc.estimate_gas().await.unwrap(),
461+
};
462+
463+
let post_inc = counter.incrementCounter("post".to_string());
464+
let post_hook = Hook {
465+
target: counter.address().into_legacy(),
466+
call_data: post_inc.calldata().to_vec(),
467+
gas_limit: post_inc.estimate_gas().await.unwrap(),
468+
};
469+
457470
tracing::info!("Placing order");
458471
let order = OrderCreation {
459472
sell_token: onchain.contracts().weth.address(),
@@ -467,8 +480,8 @@ async fn partial_fills(web3: Web3) {
467480
full: json!({
468481
"metadata": {
469482
"hooks": {
470-
"pre": [hook_for_transaction(counter.increment_counter("pre".to_string()).tx).await],
471-
"post": [hook_for_transaction(counter.increment_counter("post".to_string()).tx).await],
483+
"pre": [pre_hook],
484+
"post": [post_hook],
472485
},
473486
},
474487
})
@@ -496,13 +509,10 @@ async fn partial_fills(web3: Web3) {
496509
== 0.into()
497510
};
498511
wait_for_condition(TIMEOUT, trade_happened).await.unwrap();
499-
assert_eq!(
500-
counter.counters("pre".to_string()).call().await.unwrap(),
501-
1.into()
502-
);
512+
assert_eq!(counter.counters("pre".to_string()).call().await.unwrap(), 1);
503513
assert_eq!(
504514
counter.counters("post".to_string()).call().await.unwrap(),
505-
1.into()
515+
1
506516
);
507517

508518
tracing::info!("Fund remaining sell balance.");
@@ -514,13 +524,10 @@ async fn partial_fills(web3: Web3) {
514524

515525
tracing::info!("Waiting for second trade.");
516526
wait_for_condition(TIMEOUT, trade_happened).await.unwrap();
517-
assert_eq!(
518-
counter.counters("pre".to_string()).call().await.unwrap(),
519-
1.into()
520-
);
527+
assert_eq!(counter.counters("pre".to_string()).call().await.unwrap(), 1);
521528
assert_eq!(
522529
counter.counters("post".to_string()).call().await.unwrap(),
523-
2.into()
530+
2
524531
);
525532
}
526533

0 commit comments

Comments
 (0)