Skip to content

Commit 2f77201

Browse files
committed
Add arb_wasm test
1 parent 94b3523 commit 2f77201

File tree

4 files changed

+90
-1
lines changed

4 files changed

+90
-1
lines changed

integration/stylus/arb_wasm.sol

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity >=0.8.0;
3+
4+
interface ArbWasm {
5+
/// @notice Activate a wasm program
6+
/// @param program the program to activate
7+
/// @return version the stylus version the program was activated against
8+
/// @return dataFee the data fee paid to store the activated program
9+
function activateProgram(
10+
address program
11+
) external payable returns (uint16 version, uint256 dataFee);
12+
}
13+
14+
contract C is ArbWasm {
15+
function forwardActivateProgram(
16+
address target,
17+
address program
18+
) public payable returns (uint16, uint256) {
19+
print("target = {}".format(target));
20+
(uint16 version, uint256 dataFee) = ArbWasm(target).activateProgram{
21+
value: msg.value
22+
}(program);
23+
print("version = {}".format(version));
24+
print("dataFee = {}".format(dataFee));
25+
return (version, dataFee);
26+
}
27+
28+
function activateProgram(
29+
address program
30+
) public payable returns (uint16, uint256) {
31+
print("program = {}".format(program));
32+
uint256 value = msg.value;
33+
print("value = {}".format(value));
34+
return (1, 1000);
35+
}
36+
}
37+
38+
contract D {
39+
function greet() public pure {
40+
print("Hello!");
41+
}
42+
}

tests/stylus_tests/arb_wasm.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//! This test expects you to have a devnode running:
2+
//! <https://docs.arbitrum.io/run-arbitrum-node/run-nitro-dev-node>
3+
//!
4+
//! It also expects `cargo-stylus` and `cast` to be installed:
5+
//! - <https://github.com/OffchainLabs/cargo-stylus>
6+
//! - <https://book.getfoundry.sh/cast/>
7+
#![warn(clippy::pedantic)]
8+
9+
use crate::{call, deploy, send, MUTEX};
10+
use std::path::PathBuf;
11+
12+
#[test]
13+
fn arb_wasm() {
14+
let _lock = MUTEX.lock();
15+
16+
let (tempdir, address_c) = deploy(
17+
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("integration/stylus/arb_wasm.sol"),
18+
"C",
19+
true,
20+
)
21+
.unwrap();
22+
let dir_c = &tempdir;
23+
24+
let (tempdir, address_d) = deploy(
25+
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("integration/stylus/arb_wasm.sol"),
26+
"D",
27+
false,
28+
)
29+
.unwrap();
30+
let dir_d = &tempdir;
31+
32+
let stdout = send(
33+
dir_c,
34+
&address_c,
35+
[
36+
"forwardActivateProgram(address,address)",
37+
&format!("0x{:0>40x}", 0x71),
38+
&address_d,
39+
"--value=1000000000000000000",
40+
],
41+
)
42+
.unwrap();
43+
println!("{}", &stdout);
44+
45+
let stdout = call(dir_d, &address_d, ["greet()"]).unwrap();
46+
println!("{}", &stdout);
47+
}

tests/stylus_tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mod api;
2+
mod arb_wasm;
23
mod counter;
34
mod milestone_1;
45
mod milestone_2;

tests/stylus_tests/value.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ fn value() {
1515
let (tempdir, address) = deploy(
1616
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("integration/stylus/value.sol"),
1717
"C",
18-
true,
1918
)
2019
.unwrap();
2120
let dir = &tempdir;

0 commit comments

Comments
 (0)