Skip to content

Commit 0fd1bd3

Browse files
committed
Add ERC20 test
1 parent 640ceae commit 0fd1bd3

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
pragma solidity =0.5.16;
22

3-
import '../UniswapV2ERC20.sol';
3+
import "../UniswapV2ERC20.sol";
44

55
contract ERC20 is UniswapV2ERC20 {
6-
constructor(uint _totalSupply) public {
6+
bool inited;
7+
8+
function init(uint _totalSupply) public {
9+
require(!inited);
710
_mint(msg.sender, _totalSupply);
11+
inited = true;
812
}
913
}

tests/stylus_tests/erc20.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 erc20() {
14+
let _lock = MUTEX.lock();
15+
let (tempdir, address) = deploy(
16+
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("integration/stylus/Uniswap/test/ERC20.sol"),
17+
"ERC20",
18+
true,
19+
)
20+
.unwrap();
21+
let dir = &tempdir;
22+
23+
let balance = concat!("1000000", "000000000000000000");
24+
25+
let stdout = call(dir, &address, ["totalSupply()(uint256)"]).unwrap();
26+
println!("{}", stdout);
27+
assert_eq!("0\n", stdout);
28+
29+
let stdout = send(dir, &address, ["init(uint256)", balance]).unwrap();
30+
println!("{}", stdout);
31+
32+
// smoelius: Calling `init` a second time should revert.
33+
let error = send(dir, &address, ["init(uint256)", balance]).unwrap_err();
34+
println!("{:?}", error);
35+
36+
let stdout = call(dir, &address, ["totalSupply()(uint256)"]).unwrap();
37+
println!("{}", stdout);
38+
assert_eq!("1000000000000000000000000 [1e24]\n", stdout);
39+
}

tests/stylus_tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ mod arb_wasm;
33
mod counter;
44
mod create2;
55
mod ecrecover;
6+
mod erc20;
67
mod milestone_1;
78
mod milestone_2;
89
mod milestone_3;

0 commit comments

Comments
 (0)