ethers-rs/tests/live/celo.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

60 lines
2.3 KiB
Rust
Raw Normal View History

ci/test: improve CI jobs and tests (#2189) * ci: move to scripts directory * nits * ci: improve main CI jobs * fix: install script * fix * fix: use curl for windows installation * fix: wasm typo * tests: move to single binary * chore: clippy * chore: clippy * chore: clippy * fix: test command * fix: quote tests * update script * fix: action exclude * fix: dev deps * fix: only run wasm in own job * ci: add aarch64 targets * test: rm useless test * ci: update security audit * ci: add deny CI * chore: rm unused audit.toml * chore: update geth.rs * ci: remove unusable targets * fix: install script path * fix: wasm * improve script * fix: failing ci * fix: contract tests * ci: improve install script * update middleware tests * move integration etherscan tests to tests/ dir * fix: eip2930 access_list field name * add pendingtransaction must_use * add random anvil comment * ci: add miri job * ci: simplify * fixci * Revert "add pendingtransaction must_use" This reverts commit 770b21b4a3c6ef8900a6aa1cd46aa9638317a60d. * fix: macos script * fix: use curl in script * unused ci * update script * fix wasm * rm_miri * fix: signer test * fix: wasm ci * fix: ipc test * fix: live celo tests * fix: abi online source test * fix: windows paths in test * chore: update serial_test * ci: run live tests separately * fix: provider tests * fix: unused var * fix: feature * fix merge * fix: etherscan key tests * ci: rm duplicate audit * fix: split etherscan test ci * fix: etherscan test * fix: generate multiple unused ports * fix: source test * fix: udeps * rm unused
2023-03-01 00:26:27 +00:00
use crate::simple_storage::SimpleStorage;
use ethers::prelude::*;
use std::{sync::Arc, time::Duration};
static CELO_TESTNET_URL: &str = "https://alfajores-forno.celo-testnet.org";
#[tokio::test]
async fn test_send_transaction() {
// Celo testnet
let provider =
Provider::<Http>::try_from(CELO_TESTNET_URL).unwrap().interval(Duration::from_secs(3));
let chain_id = provider.get_chainid().await.unwrap().as_u64();
// Funded with https://celo.org/developers/faucet
// Please do not drain this account :)
let wallet = "d652abb81e8c686edba621a895531b1f291289b63b5ef09a94f686a5ecdd5db1"
.parse::<LocalWallet>()
.unwrap()
.with_chain_id(chain_id);
let client = SignerMiddleware::new(provider, wallet);
let balance_before = client.get_balance(client.address(), None).await.unwrap();
let tx = TransactionRequest::pay(client.address(), 100);
let _receipt = client.send_transaction(tx, None).await.unwrap().confirmations(3).await.unwrap();
let balance_after = client.get_balance(client.address(), None).await.unwrap();
assert!(balance_before > balance_after);
}
#[tokio::test]
async fn deploy_and_call_contract() {
// Celo testnet
let provider =
Provider::<Http>::try_from(CELO_TESTNET_URL).unwrap().interval(Duration::from_secs(3));
let chain_id = provider.get_chainid().await.unwrap().as_u64();
// Funded with https://celo.org/developers/faucet
let wallet = "58ea5643a78c36926ad5128a6b0d8dfcc7fc705788a993b1c724be3469bc9697"
.parse::<LocalWallet>()
.unwrap()
.with_chain_id(chain_id);
let client = provider.with_signer(wallet);
let client = Arc::new(client);
let deploy_tx = SimpleStorage::deploy(client, ()).unwrap();
let contract = deploy_tx.send().await.unwrap();
let value: U256 = contract.value().call().await.unwrap();
assert_eq!(value, 0.into());
// make a state mutating transaction
// gas estimation costs are sometimes under-reported on celo,
// so we manually set it to avoid failures
let call = contract.set_value(1.into()).gas(100000);
let pending_tx = call.send().await.unwrap();
let _receipt = pending_tx.await.unwrap();
let value: U256 = contract.method("value", ()).unwrap().call().await.unwrap();
assert_eq!(value, 1.into());
}