forked from keep-starknet-strange/zkramp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first commit : bug:external contracts not found for selectors: `openz…
…eppelin::presets::ERC20Upgradeable`
- Loading branch information
Showing
10 changed files
with
135 additions
and
9 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,2 +1,2 @@ | ||
target | ||
.snfoundry_cache/ | ||
.snfoundry_cache |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
zkramp::components::escrow::escrow_test::test_lock_unlock |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
scarb 2.7.0 |
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
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,3 +1,9 @@ | ||
pub mod escrow; | ||
|
||
#[cfg(test)] | ||
pub mod escrow_mock; | ||
|
||
#[cfg(test)] | ||
pub mod escrow_test; | ||
pub mod interface; | ||
|
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
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use super::escrow::EscrowComponent; | ||
|
||
#[starknet::contract] | ||
pub mod EscrowMock { | ||
use starknet::ContractAddress; | ||
use starknet::account::Call; | ||
use zkramp::components::escrow::escrow::EscrowComponent; | ||
use zkramp::components::escrow::interface::IEscrow; | ||
|
||
component!(path: EscrowComponent, storage: escrow, event: EscrowEvent); | ||
|
||
// Escrow | ||
#[abi(embed_v0)] | ||
impl EscrowImpl = EscrowComponent::EscrowImpl<ContractState>; | ||
|
||
// | ||
// Storage | ||
// | ||
|
||
#[storage] | ||
struct Storage { | ||
#[substorage(v0)] | ||
escrow: EscrowComponent::Storage, | ||
} | ||
|
||
// | ||
// Events | ||
// | ||
|
||
#[event] | ||
#[derive(Drop, starknet::Event)] | ||
enum Event { | ||
#[flat] | ||
EscrowEvent: EscrowComponent::Event, | ||
} | ||
|
||
// | ||
// Constructor | ||
// | ||
|
||
#[constructor] | ||
fn constructor(ref self: ContractState) { // Nothing to be done | ||
} | ||
} | ||
|
||
pub type ComponentState = EscrowComponent::ComponentState<EscrowMock::ContractState>; | ||
|
||
pub impl TestingStateDefault of Default<ComponentState> { | ||
fn default() -> ComponentState { | ||
EscrowComponent::component_state_for_testing() | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use core::starknet::get_contract_address; | ||
|
||
use openzeppelin::presets::interfaces::ERC20UpgradeableABIDispatcherTrait; | ||
|
||
use zkramp::components::escrow::escrow::EscrowComponent::EscrowImpl; | ||
use zkramp::components::escrow::escrow_mock::{EscrowMock, TestingStateDefault, ComponentState}; | ||
|
||
use zkramp::tests::constants; | ||
use zkramp::tests::utils; | ||
|
||
|
||
// | ||
// Externals | ||
// | ||
|
||
#[test] | ||
fn test_lock_unlock() { | ||
let token_dispatcher = utils::setup_erc20(recipient: get_contract_address()); | ||
|
||
token_dispatcher.transfer(constants::OWNER(), 100); | ||
|
||
let mut escrow: ComponentState = Default::default(); | ||
|
||
escrow.lock_from(constants::OWNER(), token_dispatcher.contract_address, 42); | ||
|
||
escrow | ||
.unlock_to(constants::OWNER(), constants::CALLER(), token_dispatcher.contract_address, 42); | ||
|
||
assert_eq!(escrow.deposits.read((constants::OWNER(), token_dispatcher.contract_address)), 0); | ||
} | ||
|
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
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,10 +1,29 @@ | ||
use starknet::{SyscallResultTrait, syscalls}; | ||
use core::traits::TryInto; | ||
|
||
pub fn deploy(contract_class_hash: felt252, calldata: Array<felt252>) -> starknet::ContractAddress { | ||
let (address, _) = syscalls::deploy_syscall( | ||
contract_class_hash.try_into().unwrap(), 0, calldata.span(), false | ||
) | ||
.unwrap_syscall(); | ||
use openzeppelin::presets::interfaces::{ | ||
ERC20UpgradeableABIDispatcher, ERC20UpgradeableABIDispatcherTrait | ||
}; | ||
|
||
address | ||
use openzeppelin::utils::serde::SerializedAppend; | ||
|
||
use snforge_std::{declare, ContractClassTrait}; | ||
use starknet::ContractAddress; | ||
|
||
use super::constants; | ||
|
||
|
||
pub fn setup_erc20(recipient: ContractAddress) -> ERC20UpgradeableABIDispatcher { | ||
let mut calldata = array![]; | ||
|
||
calldata.append_serde(constants::NAME()); | ||
calldata.append_serde(constants::SYMBOL()); | ||
calldata.append_serde(constants::SUPPLY); // 1 ETH | ||
calldata.append_serde(recipient); | ||
calldata.append_serde(recipient); | ||
|
||
let contract = declare("ERC20Upgradeable").unwrap(); | ||
let (contract_address, _) = contract.deploy(@calldata).unwrap(); | ||
|
||
ERC20UpgradeableABIDispatcher { contract_address: contract_address } | ||
} | ||
|