From 30c5056366d86d5baa451b6ae222912af5e1623b Mon Sep 17 00:00:00 2001 From: Angry Coding Date: Tue, 5 Nov 2024 09:06:22 +0000 Subject: [PATCH] chore: tests --- target_chains/ethereum/sdk/stylus/Cargo.lock | 1 + .../stylus/examples/function-calls/src/lib.rs | 1 + .../examples/function-calls/tests/abi/mod.rs | 66 +++---------------- .../function-calls/tests/function-calls.rs | 31 ++++++--- .../examples/proxy-calls/tests/proxy-calls.rs | 16 ++--- 5 files changed, 42 insertions(+), 73 deletions(-) diff --git a/target_chains/ethereum/sdk/stylus/Cargo.lock b/target_chains/ethereum/sdk/stylus/Cargo.lock index 44a77c487..fedc1e57f 100644 --- a/target_chains/ethereum/sdk/stylus/Cargo.lock +++ b/target_chains/ethereum/sdk/stylus/Cargo.lock @@ -791,6 +791,7 @@ dependencies = [ "koba", "pyth-stylus", "serde", + "stylus-sdk", "tokio", ] diff --git a/target_chains/ethereum/sdk/stylus/examples/function-calls/src/lib.rs b/target_chains/ethereum/sdk/stylus/examples/function-calls/src/lib.rs index 18cd3a53e..f5a0afc5d 100644 --- a/target_chains/ethereum/sdk/stylus/examples/function-calls/src/lib.rs +++ b/target_chains/ethereum/sdk/stylus/examples/function-calls/src/lib.rs @@ -51,6 +51,7 @@ pub enum MultiCallErrors { impl FunctionCallsExample { pub fn get_price_unsafe(&mut self) -> Result<(), Vec> { let price = get_price_unsafe(self, self.pyth_address.get(), self.price_id.get())?; + self.price.set(price); if price.price > 0 { return Ok(()); } diff --git a/target_chains/ethereum/sdk/stylus/examples/function-calls/tests/abi/mod.rs b/target_chains/ethereum/sdk/stylus/examples/function-calls/tests/abi/mod.rs index 34ec44e34..fc8202dca 100644 --- a/target_chains/ethereum/sdk/stylus/examples/function-calls/tests/abi/mod.rs +++ b/target_chains/ethereum/sdk/stylus/examples/function-calls/tests/abi/mod.rs @@ -3,62 +3,14 @@ use alloy::sol; sol!( #[sol(rpc)] - contract Pyth { - function approve(address to, uint256 tokenId) external; - #[derive(Debug)] - function balanceOf(address owner) external view returns (uint256 balance); - #[derive(Debug)] - function getApproved(uint256 tokenId) external view returns (address approved); - #[derive(Debug)] - function isApprovedForAll(address owner, address operator) external view returns (bool approved); - #[derive(Debug)] - function ownerOf(uint256 tokenId) external view returns (address ownerOf); - function safeTransferFrom(address from, address to, uint256 tokenId) external; - function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external; - function setApprovalForAll(address operator, bool approved) external; - function totalSupply() external view returns (uint256 totalSupply); - function transferFrom(address from, address to, uint256 tokenId) external; - - function mint(address to, uint256 tokenId) external; - function burn(uint256 tokenId) external; - - function paused() external view returns (bool paused); - function pause() external; - function unpause() external; - #[derive(Debug)] - function whenPaused() external view; - #[derive(Debug)] - function whenNotPaused() external view; - - #[derive(Debug)] - function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId); - #[derive(Debug)] - function tokenByIndex(uint256 index) external view returns (uint256 tokenId); - - function supportsInterface(bytes4 interface_id) external view returns (bool supportsInterface); - - error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner); - error ERC721InsufficientApproval(address operator, uint256 tokenId); - error ERC721InvalidApprover(address approver); - error ERC721InvalidOperator(address operator); - error ERC721InvalidOwner(address owner); - error ERC721InvalidReceiver(address receiver); - error ERC721InvalidSender(address sender); - error ERC721NonexistentToken(uint256 tokenId); - error ERC721OutOfBoundsIndex(address owner, uint256 index); - error ERC721EnumerableForbiddenBatchMint(); - error EnforcedPause(); - error ExpectedPause(); - - #[derive(Debug, PartialEq)] - event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); - #[derive(Debug, PartialEq)] - event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); - #[derive(Debug, PartialEq)] - event ApprovalForAll(address indexed owner, address indexed operator, bool approved); - #[derive(Debug, PartialEq)] - event Paused(address account); - #[derive(Debug, PartialEq)] - event Unpaused(address account); + contract FunctionCalls { + function getPriceUnsafe() external ; + function getEmaPriceUnsafe() external ; + function getPriceNoOlderThan() external ; + function getEmaPriceNoOlderThan() external; + function getUpdateFee() external; + function getValidTimePeriod() external; + function updatePriceFeeds() external payable; + function updatePriceFeedsIfNecessary() external payable; } ); \ No newline at end of file diff --git a/target_chains/ethereum/sdk/stylus/examples/function-calls/tests/function-calls.rs b/target_chains/ethereum/sdk/stylus/examples/function-calls/tests/function-calls.rs index acad6a37a..c9d874fbd 100644 --- a/target_chains/ethereum/sdk/stylus/examples/function-calls/tests/function-calls.rs +++ b/target_chains/ethereum/sdk/stylus/examples/function-calls/tests/function-calls.rs @@ -1,20 +1,35 @@ #![cfg(feature = "e2e")] -use alloy::hex; -use e2e::{receipt,ReceiptExt,Account}; +use abi::FunctionCalls; +use alloy::{ + primitives::{uint, Address, U256}, + sol, +}; +use e2e::{ + receipt, send, watch, Account, EventExt, Panic, PanicCode, ReceiptExt, + Revert, +}; use eyre::Result; +// use crate::FunctionCallsExample::constructorCall; + mod abi; +sol!("src/constructor.sol"); // // ============================================================================ // // Integration Tests: Function Calls // // ============================================================================ - #[e2e::test] -async fn constructs(alice: Account) -> Result<()> { - let contract_addr = alice.as_deployer().deploy().await?.address()?; -// // assert_eq!(true, true); +// #[e2e::test] +// async fn constructs(alice: Account) -> Result<()> { +// let contract_addr = alice +// .as_deployer() +// .with_default_constructor::() +// .deploy() +// .await? +// .address()?; +// // // assert_eq!(true, true); - Ok(()) - } +// Ok(()) +// } diff --git a/target_chains/ethereum/sdk/stylus/examples/proxy-calls/tests/proxy-calls.rs b/target_chains/ethereum/sdk/stylus/examples/proxy-calls/tests/proxy-calls.rs index d56528ce4..57bba732d 100644 --- a/target_chains/ethereum/sdk/stylus/examples/proxy-calls/tests/proxy-calls.rs +++ b/target_chains/ethereum/sdk/stylus/examples/proxy-calls/tests/proxy-calls.rs @@ -1,20 +1,20 @@ #![cfg(feature = "e2e")] -use alloy::hex; +use alloy::{hex, sol}; use e2e::{receipt,ReceiptExt,Account}; use eyre::Result; mod abi; - +sol!("src/constructor.sol"); // // ============================================================================ // // Integration Tests: Proxy Calls // // ============================================================================ - #[e2e::test] -async fn constructs(alice: Account) -> Result<()> { - // let contract_addr = alice.as_deployer().deploy().await?.address()?; -// // assert_eq!(true, true); +// #[e2e::test] +// async fn constructs(alice: Account) -> Result<()> { +// // // let contract_addr = alice.as_deployer().deploy().await?.address()?; +// // // // assert_eq!(true, true); - Ok(()) - } +// Ok(()) +// }