Skip to content

Commit

Permalink
env and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Ifechukwudaniel committed Nov 5, 2024
1 parent 30c5056 commit 908b866
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 85 deletions.
1 change: 1 addition & 0 deletions target_chains/ethereum/sdk/stylus/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ use alloy::{
sol,
sol_types::{SolCall, SolConstructor},
};
use e2e::{receipt, Account};
use e2e::{receipt, Account, env};

use crate::{
env, report::{ContractReport, FunctionReport}, CacheOpt
};
use crate::{ report::{ContractReport, FunctionReport}, CacheOpt};

sol!(
#[sol(rpc)]
Expand Down
4 changes: 2 additions & 2 deletions target_chains/ethereum/sdk/stylus/benches/src/proxy_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use alloy::{
providers::ProviderBuilder,
sol, sol_types::{ SolCall, SolConstructor}
};
use e2e::{receipt, Account};
use e2e::{receipt, Account, env};
use pyth_stylus::pyth::mock::create_price_feed_update_data_list;

use crate::{
env, report::{ContractReport, FunctionReport}, CacheOpt
report::{ContractReport, FunctionReport}, CacheOpt
};

sol!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ version.workspace = true

[dependencies]
pyth-stylus.workspace = true
alloy-primitives.workspace = true
alloy-primitives = { workspace = true, features = ["tiny-keccak"] }
alloy-sol-types.workspace = true
stylus-sdk.workspace = true
mini-alloc.workspace = true

keccak-const.workspace = true

[dev-dependencies]
alloy.workspace = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,76 @@
#![cfg(feature = "e2e")]

use std::println;

use abi::FunctionCalls;
use alloy::{
primitives::{uint, Address, U256},
primitives::{uint, U256},
sol,
};
use alloy_primitives::{address, Address, FixedBytes};
use e2e::{
receipt, send, watch, Account, EventExt, Panic, PanicCode, ReceiptExt,
Revert,
Revert,env
};
use eyre::Result;

// use crate::FunctionCallsExample::constructorCall;
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()
// .with_default_constructor::<constructorCall>()
// .deploy()
// .await?
// .address()?;
// // // assert_eq!(true, true);

// Ok(())
// }
fn str_to_address(input: &str) -> Address {
let mut address_bytes = [0u8; 20]; // Initialize a 20-byte array with zeros

// Convert the input string to bytes and copy into the 20-byte array
let input_bytes = input.as_bytes();
let len = input_bytes.len().min(20); // Take up to 20 bytes if input is longer

address_bytes[..len].copy_from_slice(&input_bytes[..len]);

Address::new(address_bytes) // Create an Address from the byte array
}

impl Default for constructorCall {
fn default() -> Self {
ctr("ETH")
}
}


fn ctr(key_id: &str) -> constructorCall {
let pyth_addr = env("MOCK_PYTH_ADDRESS").unwrap();
let address_addr = str_to_address(&pyth_addr);
println!("MOCK_PYTH_ADDRESS: {:?}", pyth_addr);
let id = keccak_const::Keccak256::new().update(key_id.as_bytes()).finalize().to_vec();
let price_id = FixedBytes::<32>::from_slice(&id);
constructorCall {
_pythAddress: address_addr,
_priceId: price_id
}
}

#[e2e::test]
async fn constructs(alice: Account) -> Result<()> {
// Deploy contract using `alice` account
let contract_addr = alice
.as_deployer()
.with_default_constructor::<constructorCall>() // Assuming `constructorCall` is the constructor here
.deploy()
.await?
.address()?;

// Instantiate the contract instance
let contract = FunctionCalls::new(contract_addr, &alice.wallet);

// Perform basic checks to ensure the contract is correctly initialized
// Calling a sample function to validate deployment (e.g., `getPriceUnsafe` as a placeholder)
let price_result = contract.getPriceUnsafe().call().await;

// Verify that the contract was deployed successfully and the function call does not revert
price_result.expect("The contract deployment or function call failed");
//assert!(price_result.is_ok(), "The contract deployment or function call failed");

Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 ProxyCalls {
function getPriceUnsafe(bytes32 id) external;
function getEmaPriceUnsafe(bytes32 id) external;
function getPriceNoOlderThan(bytes32 id, uint age) external;
function getEmaPriceNoOlderThan(bytes32 id, uint age) external;
function getUpdateFee(bytes[] calldata updateData) external returns (uint256);
function getValidTimePeriod() external;
function updatePriceFeeds(bytes[] calldata updateData) external payable;
function updatePriceFeedsIfNecessary(bytes[] calldata updateData, bytes32[] calldata priceIds, uint64[] calldata publishTimes) external payable;
}
);
7 changes: 7 additions & 0 deletions target_chains/ethereum/sdk/stylus/lib/e2e/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ pub use error::{Panic, PanicCode, Revert};
pub use event::EventExt;
pub use receipt::ReceiptExt;
pub use system::{fund_account, provider, Provider, Wallet};
use eyre::WrapErr;

/// Load the `name` environment variable.
pub fn env(name: &str) -> eyre::Result<String> {
std::env::var(name).wrap_err(format!("failed to load {name}"))
}

/// This macro provides a shorthand for broadcasting the transaction to the
/// network.
Expand Down Expand Up @@ -90,3 +96,4 @@ macro_rules! receipt {
$crate::send!($e)?.get_receipt().await
};
}

0 comments on commit 908b866

Please sign in to comment.