Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion crates/contract/tests/sandbox/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ use mpc_contract::{
use near_account_id::AccountId;
use near_mpc_contract_interface::types::{
Curve, DomainConfig, DomainId, DomainPurpose, Protocol, ReconstructionThreshold,
SupportedForeignChains,
SupportedForeignChains, TonAddress, TonCellBody, TonExtractedValue, TonExtractor, TonFinality,
TonLog, TonRpcRequest, TonTxId,
};
use near_mpc_contract_interface::{
method_names,
Expand Down Expand Up @@ -797,6 +798,19 @@ pub fn starknet_extracted_values() -> Vec<ExtractedValue> {
)]
}

pub fn bogus_ton_log_extracted_value() -> Vec<ExtractedValue> {
vec![ExtractedValue::TonExtractedValue(TonExtractedValue::Log(
TonLog {
from_address: TonAddress {
workchain: 0,
hash: Hash256([1; 32]),
Comment thread
DSharifi marked this conversation as resolved.
},
body: TonCellBody::new(vec![].try_into().unwrap(), 0).unwrap(),
body_refs: vec![].try_into().unwrap(),
},
))]
}

pub fn bnb_evm_request() -> ForeignChainRpcRequest {
ForeignChainRpcRequest::Bnb(EvmRpcRequest {
tx_id: EvmTxId([0xbb; 32]),
Expand Down Expand Up @@ -836,3 +850,15 @@ pub fn polygon_evm_request() -> ForeignChainRpcRequest {
finality: EvmFinality::Finalized,
})
}

pub fn ton_request() -> ForeignChainRpcRequest {
ForeignChainRpcRequest::Ton(TonRpcRequest {
tx_id: TonTxId([0xbb; 32]),
Comment thread
DSharifi marked this conversation as resolved.
extractors: vec![TonExtractor::Log { message_index: 0 }],
finality: TonFinality::MasterchainIncluded,
account: TonAddress {
workchain: 0,
hash: Hash256([1; 32]),
},
})
}
9 changes: 6 additions & 3 deletions crates/contract/tests/sandbox/foreign_chain_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
use crate::sandbox::common::{
SandboxTestSetup, abstract_evm_request, arbitrum_evm_request,
await_pending_foreign_tx_request_observed_on_contract, base_evm_request,
bitcoin_extracted_values, bitcoin_request, bnb_evm_request, ethereum_evm_request,
evm_block_hash_extracted_values, hyper_evm_request, polygon_evm_request,
bitcoin_extracted_values, bitcoin_request, bnb_evm_request, bogus_ton_log_extracted_value,
ethereum_evm_request, evm_block_hash_extracted_values, hyper_evm_request, polygon_evm_request,
register_foreign_chain_configuration, sign_foreign_tx_response, starknet_extracted_values,
starknet_request,
starknet_request, ton_request,
};
use near_mpc_contract_interface::method_names;
use near_mpc_contract_interface::types::{
Expand All @@ -29,6 +29,7 @@ const SIGNATURE_TIMEOUT_BLOCKS: u64 = 200;
#[case::arbitrum(arbitrum_evm_request(), evm_block_hash_extracted_values())]
#[case::polygon(polygon_evm_request(), evm_block_hash_extracted_values())]
#[case::hyper_evm(hyper_evm_request(), evm_block_hash_extracted_values())]
#[case::ton(ton_request(), bogus_ton_log_extracted_value())]
#[tokio::test]
async fn verify_foreign_transaction__should_succeed(
#[case] rpc_request: ForeignChainRpcRequest,
Expand Down Expand Up @@ -201,6 +202,7 @@ async fn verify_foreign_transaction__should_fan_out_response_to_duplicates_from_
#[case::arbitrum(arbitrum_evm_request())]
#[case::polygon(polygon_evm_request())]
#[case::hyper_evm(hyper_evm_request())]
#[case::ton(ton_request())]
#[tokio::test]
async fn verify_foreign_transaction__should_reject_without_policy(
#[case] rpc_request: ForeignChainRpcRequest,
Expand Down Expand Up @@ -247,6 +249,7 @@ async fn verify_foreign_transaction__should_reject_without_policy(
#[case::arbitrum(arbitrum_evm_request())]
#[case::polygon(polygon_evm_request())]
#[case::hyper_evm(hyper_evm_request())]
#[case::ton(ton_request())]
#[tokio::test]
async fn verify_foreign_transaction__should_timeout_without_response(
#[case] rpc_request: ForeignChainRpcRequest,
Expand Down
109 changes: 108 additions & 1 deletion crates/contract/tests/snapshots/abi__abi_has_not_changed.snap
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ expression: abi
9,
"HyperEvm",
"ForeignChain__HyperEvm"
],
[
10,
"Ton",
"ForeignChain__Ton"
]
]
}
Expand Down Expand Up @@ -275,6 +280,9 @@ expression: abi
"ForeignChain__Starknet": {
"Struct": null
},
"ForeignChain__Ton": {
"Struct": null
},
"NonEmptyBTreeMap<ProviderId, ProviderConfig>": {
"Sequence": {
"length_width": 4,
Expand Down Expand Up @@ -2051,6 +2059,11 @@ expression: abi
9,
"HyperEvm",
"ForeignChain__HyperEvm"
],
[
10,
"Ton",
"ForeignChain__Ton"
]
]
}
Expand Down Expand Up @@ -2085,6 +2098,9 @@ expression: abi
"ForeignChain__Starknet": {
"Struct": null
},
"ForeignChain__Ton": {
"Struct": null
},
"NonEmptyBTreeMap<ForeignChain, ChainEntry>": {
"Sequence": {
"length_width": 4,
Expand Down Expand Up @@ -2878,7 +2894,8 @@ expression: abi
"Abstract",
"Starknet",
"Polygon",
"HyperEvm"
"HyperEvm",
"Ton"
]
},
"ForeignChainConfiguration": {
Expand Down Expand Up @@ -3009,6 +3026,18 @@ expression: abi
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"Ton"
],
"properties": {
"Ton": {
"$ref": "#/definitions/TonRpcRequest"
}
},
"additionalProperties": false
}
]
},
Expand Down Expand Up @@ -4580,6 +4609,84 @@ expression: abi
}
}
},
"TonAddress": {
"type": "object",
"required": [
"hash",
"workchain"
],
"properties": {
"hash": {
"$ref": "#/definitions/Hash256"
},
"workchain": {
"type": "integer",
"format": "int32"
}
}
},
"TonExtractor": {
"oneOf": [
{
"type": "object",
"required": [
"Log"
],
"properties": {
"Log": {
"type": "object",
"required": [
"message_index"
],
"properties": {
"message_index": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
}
}
},
"additionalProperties": false
}
]
},
"TonFinality": {
"type": "string",
"enum": [
"MasterchainIncluded"
]
},
"TonRpcRequest": {
"type": "object",
"required": [
"account",
"extractors",
"finality",
"tx_id"
],
"properties": {
"account": {
"$ref": "#/definitions/TonAddress"
},
"extractors": {
"type": "array",
"items": {
"$ref": "#/definitions/TonExtractor"
}
},
"finality": {
"$ref": "#/definitions/TonFinality"
},
"tx_id": {
"$ref": "#/definitions/TonTxId"
}
}
},
"TonTxId": {
"type": "string",
"pattern": "^(?:[0-9A-Fa-f]{2})*$"
},
"Tweak": {
"type": "array",
"items": {
Expand Down
Loading
Loading