Skip to content

Commit

Permalink
update for new piltover, scarb version, and tests (#14)
Browse files Browse the repository at this point in the history
* update for new piltover, scarb version, and tests

* chore: ran formatter

* add comment for payload
  • Loading branch information
byteZorvin authored Sep 7, 2024
1 parent 6ee821b commit 5317c7d
Show file tree
Hide file tree
Showing 21 changed files with 212 additions and 201 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
scarb 2.6.5
scarb 2.8.0
starknet-foundry 0.27.0
92 changes: 89 additions & 3 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,99 @@ version = 1

[[package]]
name = "openzeppelin"
version = "0.14.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.14.0#f091c4f51ddeb10297db984acae965328c5a4e5b"
version = "0.16.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb"
dependencies = [
"openzeppelin_access",
"openzeppelin_account",
"openzeppelin_governance",
"openzeppelin_introspection",
"openzeppelin_merkle_tree",
"openzeppelin_presets",
"openzeppelin_security",
"openzeppelin_token",
"openzeppelin_upgrades",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_access"
version = "0.16.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb"
dependencies = [
"openzeppelin_introspection",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_account"
version = "0.16.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb"
dependencies = [
"openzeppelin_introspection",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_governance"
version = "0.16.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb"
dependencies = [
"openzeppelin_access",
"openzeppelin_introspection",
]

[[package]]
name = "openzeppelin_introspection"
version = "0.16.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb"

[[package]]
name = "openzeppelin_merkle_tree"
version = "0.16.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb"

[[package]]
name = "openzeppelin_presets"
version = "0.16.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb"
dependencies = [
"openzeppelin_access",
"openzeppelin_account",
"openzeppelin_introspection",
"openzeppelin_token",
"openzeppelin_upgrades",
]

[[package]]
name = "openzeppelin_security"
version = "0.16.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb"

[[package]]
name = "openzeppelin_token"
version = "0.16.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb"
dependencies = [
"openzeppelin_account",
"openzeppelin_governance",
"openzeppelin_introspection",
]

[[package]]
name = "openzeppelin_upgrades"
version = "0.16.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb"

[[package]]
name = "openzeppelin_utils"
version = "0.16.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb"

[[package]]
name = "piltover"
version = "0.1.0"
source = "git+https://github.com/byteZorvin/piltover?branch=bridge-testing#a4021a0bb5e1638e3aebf634f5810ebb17da6a38"
source = "git+https://github.com/keep-starknet-strange/piltover?branch=main#a40db0ba727a8ae5497286341293708edcaca118"
dependencies = [
"openzeppelin",
]
Expand Down
4 changes: 2 additions & 2 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ edition = "2023_11"
# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html

[dependencies]
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.14.0" }
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.16.0" }
starknet = "2.6.4"
piltover = { git = "https://github.com/byteZorvin/piltover", branch="bridge-testing"}
piltover = { git = "https://github.com/keep-starknet-strange/piltover", branch="main"}

[dev-dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.27.0" }
Expand Down
2 changes: 1 addition & 1 deletion src/bridge/interface.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use starknet::ContractAddress;
use starknet_bridge::bridge::types::{TokenStatus, TokenSettings};
use starknet_bridge::bridge::types::TokenStatus;

#[starknet::interface]
pub trait ITokenBridgeAdmin<TContractState> {
Expand Down
37 changes: 15 additions & 22 deletions src/bridge/tests/messaging_test.cairo
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
use piltover::messaging::interface::IMessagingDispatcherTrait;
use starknet_bridge::bridge::token_bridge::TokenBridge::{
__member_module_appchain_bridge::InternalContractMemberStateTrait,
__member_module_token_settings::InternalContractMemberStateTrait as tokenSettingsStateTrait,
TokenBridgeInternal
};
use starknet_bridge::bridge::token_bridge::TokenBridge::{TokenBridgeInternal};
use snforge_std as snf;
use snforge_std::ContractClassTrait;
use starknet::{ContractAddress, storage::StorageMemberAccessTrait};
use starknet_bridge::mocks::{
messaging::{IMockMessagingDispatcherTrait, IMockMessagingDispatcher}, erc20::ERC20, hash
messaging::{IMockMessagingDispatcherTrait, IMockMessagingDispatcher}, hash
};
use starknet_bridge::bridge::TokenBridge;
use piltover::messaging::interface::IMessagingDispatcher;
use starknet_bridge::bridge::{
ITokenBridge, ITokenBridgeAdmin, ITokenBridgeDispatcher, ITokenBridgeDispatcherTrait,
ITokenBridgeAdminDispatcher, ITokenBridgeAdminDispatcherTrait, IWithdrawalLimitStatusDispatcher,
IWithdrawalLimitStatusDispatcherTrait, TokenBridge, TokenBridge::Event,
types::{TokenStatus, TokenSettings},
tests::constants::{OWNER, L3_BRIDGE_ADDRESS, USDC_MOCK_ADDRESS, DELAY_TIME}
};
use openzeppelin::{
token::erc20::interface::{IERC20MetadataDispatcher, IERC20MetadataDispatcherTrait},
access::ownable::{
OwnableComponent, OwnableComponent::Event as OwnableEvent,
interface::{IOwnableTwoStepDispatcher, IOwnableTwoStepDispatcherTrait}
}
tests::constants::{L3_BRIDGE_ADDRESS, OWNER, USDC_MOCK_ADDRESS, DELAY_TIME}
};

use piltover::messaging::types::MessageToAppchainStatus;
use starknet_bridge::bridge::tests::utils::setup::{deploy_erc20, mock_state_testing};
use starknet_bridge::bridge::tests::utils::message_payloads;
use starknet::contract_address::{contract_address_const};
Expand All @@ -37,7 +24,7 @@ fn deploy_message_payload_ok() {
let calldata = TokenBridge::deployment_message_payload(usdc_address);

let expected_calldata: Span<felt252> = array![
3346236667719676623895870229889359551507408296949803518172317961543243553075, // usdc_address
327360033215303420453874031627788877836422131767619347074434581266068999983, // usdc_address
0,
1431520323, // -- USDC
4,
Expand Down Expand Up @@ -89,7 +76,10 @@ fn send_deploy_message_ok() {
constants::HANDLE_TOKEN_DEPLOYMENT_SELECTOR,
message_payloads::deployment_message_payload(usdc_address)
);
assert(messaging.sn_to_appchain_messages(hash) == 1, 'Message not recieved');
assert(
messaging.sn_to_appchain_messages(hash) == MessageToAppchainStatus::Pending(1),
'Message not recieved'
);
}

#[test]
Expand Down Expand Up @@ -135,7 +125,10 @@ fn send_deposit_message_ok() {
)
);

assert(messaging.sn_to_appchain_messages(hash) == 1, 'Message not recieved');
assert(
messaging.sn_to_appchain_messages(hash) == MessageToAppchainStatus::Pending(1),
'Message not recieved'
);
}

#[test]
Expand Down
33 changes: 4 additions & 29 deletions src/bridge/tests/token_actions_test.cairo
Original file line number Diff line number Diff line change
@@ -1,33 +1,8 @@
use piltover::messaging::interface::IMessagingDispatcherTrait;
use starknet_bridge::bridge::token_bridge::TokenBridge::__member_module_appchain_bridge::InternalContractMemberStateTrait;
use starknet_bridge::bridge::token_bridge::TokenBridge::TokenBridgeInternal;
use starknet_bridge::bridge::token_bridge::TokenBridge::__member_module_token_settings::InternalContractMemberStateTrait as tokenSettingsStateTrait;
use snforge_std as snf;
use snforge_std::ContractClassTrait;
use starknet::{ContractAddress, storage::StorageMemberAccessTrait};
use starknet_bridge::mocks::{
messaging::{IMockMessagingDispatcherTrait, IMockMessagingDispatcher}, erc20::ERC20
};
use piltover::messaging::interface::IMessagingDispatcher;
use starknet_bridge::bridge::{
ITokenBridge, ITokenBridgeAdmin, ITokenBridgeDispatcher, ITokenBridgeDispatcherTrait,
ITokenBridgeAdminDispatcher, ITokenBridgeAdminDispatcherTrait, IWithdrawalLimitStatusDispatcher,
IWithdrawalLimitStatusDispatcherTrait, TokenBridge, TokenBridge::Event,
types::{TokenStatus, TokenSettings}
};
use openzeppelin::access::ownable::{
OwnableComponent, OwnableComponent::Event as OwnableEvent,
interface::{IOwnableTwoStepDispatcher, IOwnableTwoStepDispatcherTrait}
};
use starknet_bridge::bridge::tests::utils::message_payloads;
use starknet_bridge::mocks::hash;
use starknet::contract_address::{contract_address_const};
use starknet_bridge::constants;
use starknet_bridge::bridge::tests::utils::setup::{deploy_erc20, mock_state_testing};

use starknet_bridge::bridge::tests::constants::{
OWNER, L3_BRIDGE_ADDRESS, USDC_MOCK_ADDRESS, DELAY_TIME
};
use starknet_bridge::bridge::{ITokenBridge, ITokenBridgeAdmin, types::{TokenStatus, TokenSettings}};
use starknet_bridge::bridge::tests::utils::setup::mock_state_testing;

use starknet_bridge::bridge::tests::constants::{OWNER, USDC_MOCK_ADDRESS,};

#[test]
fn deactivate_token_ok() {
Expand Down
26 changes: 6 additions & 20 deletions src/bridge/tests/utils/setup.cairo
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
use snforge_std as snf;
use snforge_std::{
ContractClassTrait, EventSpy, EventSpyTrait, EventsFilterTrait, EventSpyAssertionsTrait
};
use starknet::{ContractAddress, storage::StorageMemberAccessTrait};
use starknet_bridge::mocks::{
messaging::{IMockMessagingDispatcherTrait, IMockMessagingDispatcher}, erc20::ERC20
};
use snforge_std::{ContractClassTrait, EventSpy};
use starknet::ContractAddress;
use starknet_bridge::mocks::{messaging::{IMockMessagingDispatcherTrait, IMockMessagingDispatcher},};
use starknet_bridge::bridge::{
ITokenBridge, ITokenBridgeAdmin, ITokenBridgeDispatcher, ITokenBridgeDispatcherTrait,
ITokenBridgeAdminDispatcher, ITokenBridgeAdminDispatcherTrait, IWithdrawalLimitStatusDispatcher,
IWithdrawalLimitStatusDispatcherTrait, TokenBridge, TokenBridge::Event,
types::{TokenStatus, TokenSettings}
};
use openzeppelin::access::ownable::{
OwnableComponent, OwnableComponent::Event as OwnableEvent,
interface::{IOwnableTwoStepDispatcher, IOwnableTwoStepDispatcherTrait}
};
use openzeppelin::token::erc20::interface::{IERC20, IERC20Dispatcher, IERC20DispatcherTrait};
use starknet::contract_address::{contract_address_const};
use starknet_bridge::bridge::tests::constants::{
OWNER, USDC_MOCK_ADDRESS, L3_BRIDGE_ADDRESS, DELAY_TIME
ITokenBridgeDispatcher, ITokenBridgeDispatcherTrait, TokenBridge, types::TokenStatus
};
use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait};
use starknet_bridge::bridge::tests::constants::{OWNER, L3_BRIDGE_ADDRESS, DELAY_TIME};
use starknet_bridge::constants;
use starknet_bridge::bridge::tests::utils::message_payloads;

Expand Down
Loading

0 comments on commit 5317c7d

Please sign in to comment.