-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6282bd0
commit f8e2af7
Showing
4 changed files
with
57 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
name: integration | ||
# TODO#q: add workflow description | ||
# This is an integration test workflow that: | ||
# - spins local nitro node | ||
# - deploys and check every contract at `./examples` directory | ||
# - runs integration test suite against all contracts deployed locally | ||
permissions: | ||
contents: read | ||
on: | ||
|
@@ -31,6 +34,7 @@ jobs: | |
toolchain: 1.77.0 | ||
- name: install cargo-stylus | ||
run: RUSTFLAGS="-C link-args=-rdynamic" cargo install [email protected] | ||
# TODO#q: cache nitro node images and nitro-testnode sources since it is a bottleneck for the routine | ||
- name: setup nitro node | ||
run: \ | ||
# clone nitro test node repo | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,63 @@ | ||
# Integration Tests | ||
## Testing Examples Contracts | ||
Deploying every contract from `./examples` and running integration tests. | ||
## Run tests | ||
Deploying every contract from `./examples` directory and running integration tests. | ||
### Against local nitro node | ||
Set up first a local nitro node according to this [guide](https://github.com/OffchainLabs/nitro-testnode/blob/release/README.md) and run this command from the project root: | ||
```terminal | ||
./integration/test.sh | ||
``` | ||
|
||
### Against stylus dev net | ||
ALICE_PRIV_KEY and BOB_PRIV_KEY should be valid funded wallets. | ||
|
||
`ALICE_PRIV_KEY` and `BOB_PRIV_KEY` should be valid funded wallets. | ||
`RPC_URL` should contain url of the stylus testnet. | ||
Run this command from the project root: | ||
```terminal | ||
ALICE_PRIV_KEY=0x... \ | ||
BOB_PRIV_KEY=0x... \ | ||
RPC_URL=https://stylus-testnet.arbitrum.io/rpc \ | ||
./integration/test.sh | ||
``` | ||
## Add test for the new contract | ||
Assuming that contract associated crate exists at `./examples` directory | ||
with the crate name `erc20-example`. | ||
Add ethereum contracts to `./integration/src/infrastructure` directory like: | ||
```rust | ||
abigen!( | ||
Erc20Token, | ||
r#"[ | ||
function decimals() external view returns (uint8) | ||
function totalSupply() external view returns (uint256) | ||
function balanceOf(address account) external view returns (uint256) | ||
function transfer(address recipient, uint256 amount) external returns (bool) | ||
function allowance(address owner, address spender) external view returns (uint256) | ||
function approve(address spender, uint256 amount) external returns (bool) | ||
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool) | ||
function mint(address account, uint256 amount) external | ||
function burn(uint256 amount) external | ||
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed) | ||
]"# | ||
); | ||
``` | ||
Then add wrapper type for the contract: | ||
```rust | ||
pub type Erc20 = Erc20Token<HttpMiddleware>; | ||
|
||
impl Token for Erc20 { | ||
const STYLUS_PROGRAM_ADDRESS: &'static str = | ||
"ERC20_EXAMPLE_DEPLOYMENT_ADDRESS"; | ||
|
||
fn new(address: Address, client: Arc<HttpMiddleware>) -> Self { | ||
Self::new(address, client) | ||
} | ||
} | ||
``` | ||
Function `new` should forward call to the contract factory method. | ||
`STYLUS_PROGRAM_ADDRESS` should have a value of formed by the template `<CRATE_NAME>_DEPLOYMENT_ADDRESS` | ||
where `<CRATE_NAME>` is the "SCREAMING_SNAKE_CASE" conversion of the crate name. | ||
`ERC20_EXAMPLE_DEPLOYMENT_ADDRESS` in this example. | ||
|
||
Tests should create new infrastructure instance like this: | ||
```rust | ||
let infra = Infrastructure::<Erc20>::new().await?; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,3 +147,5 @@ async fn error_not_approved_nft_transfer() -> Result<()> { | |
}), | ||
} | ||
} | ||
|
||
// TODO: add more tests for erc721 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters