Skip to content

Commit

Permalink
[bridge] remove test-cluster's dependency on sui-bridge crate (#19840)
Browse files Browse the repository at this point in the history
## Description 

as title. It also removes the transitive dependency of other crates on
sui-bridge.

## Test plan 

tests

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
  • Loading branch information
longbowlu authored Oct 16, 2024
1 parent 8fec5f8 commit 31b15dd
Show file tree
Hide file tree
Showing 9 changed files with 543 additions and 459 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

107 changes: 104 additions & 3 deletions crates/sui-bridge/src/e2e_tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

use crate::abi::{eth_sui_bridge, EthBridgeEvent, EthERC20, EthSuiBridge};
use crate::client::bridge_authority_aggregator::BridgeAuthorityAggregator;
use crate::e2e_tests::test_utils::BridgeTestCluster;
use crate::crypto::BridgeAuthorityKeyPair;
use crate::e2e_tests::test_utils::{
get_signatures, send_eth_tx_and_get_tx_receipt, BridgeTestClusterBuilder,
};
use crate::e2e_tests::test_utils::{BridgeTestCluster, TestClusterWrapperBuilder};
use crate::eth_transaction_builder::build_eth_transaction;
use crate::events::{
SuiBridgeEvent, SuiToEthTokenBridgeV1, TokenTransferApproved, TokenTransferClaimed,
Expand All @@ -16,11 +17,15 @@ use crate::sui_transaction_builder::build_add_tokens_on_sui_transaction;
use crate::types::{AddTokensOnEvmAction, BridgeAction, BridgeActionStatus, SuiToEthBridgeAction};
use crate::utils::publish_and_register_coins_return_add_coins_on_sui_action;
use crate::utils::EthSigner;
use crate::BRIDGE_ENABLE_PROTOCOL_VERSION;
use eth_sui_bridge::EthSuiBridgeEvents;
use ethers::prelude::*;
use ethers::types::Address as EthAddress;
use move_core_types::ident_str;
use std::collections::{HashMap, HashSet};
use sui_json_rpc_api::BridgeReadApiClient;
use sui_types::crypto::get_key_pair;
use test_cluster::TestClusterBuilder;

use std::path::Path;

Expand All @@ -32,10 +37,12 @@ use sui_json_rpc_types::{
use sui_sdk::wallet_context::WalletContext;
use sui_sdk::SuiClient;
use sui_types::base_types::{ObjectRef, SuiAddress};
use sui_types::bridge::{BridgeChainId, BridgeTokenMetadata, BRIDGE_MODULE_NAME, TOKEN_ID_ETH};
use sui_types::bridge::{
get_bridge, BridgeChainId, BridgeTokenMetadata, BridgeTrait, BRIDGE_MODULE_NAME, TOKEN_ID_ETH,
};
use sui_types::programmable_transaction_builder::ProgrammableTransactionBuilder;
use sui_types::transaction::{ObjectArg, TransactionData};
use sui_types::{TypeTag, BRIDGE_PACKAGE_ID};
use sui_types::{TypeTag, BRIDGE_PACKAGE_ID, SUI_BRIDGE_OBJECT_ID};
use tap::TapFallible;
use tracing::info;

Expand Down Expand Up @@ -327,6 +334,100 @@ async fn test_add_new_coins_on_sui_and_eth() {
.unwrap();
}

#[tokio::test(flavor = "multi_thread", worker_threads = 8)]
async fn test_create_bridge_state_object() {
let test_cluster = TestClusterBuilder::new()
.with_protocol_version((BRIDGE_ENABLE_PROTOCOL_VERSION - 1).into())
.with_epoch_duration_ms(20000)
.build()
.await;

let handles = test_cluster.all_node_handles();

// no node has the bridge state object yet
for h in &handles {
h.with(|node| {
assert!(node
.state()
.get_object_cache_reader()
.get_latest_object_ref_or_tombstone(SUI_BRIDGE_OBJECT_ID)
.unwrap()
.is_none());
});
}

// wait until feature is enabled
test_cluster
.wait_for_protocol_version(BRIDGE_ENABLE_PROTOCOL_VERSION.into())
.await;
// wait until next epoch - authenticator state object is created at the end of the first epoch
// in which it is supported.
test_cluster.wait_for_epoch_all_nodes(2).await; // protocol upgrade completes in epoch 1

for h in &handles {
h.with(|node| {
node.state()
.get_object_cache_reader()
.get_latest_object_ref_or_tombstone(SUI_BRIDGE_OBJECT_ID)
.unwrap()
.expect("auth state object should exist");
});
}
}

#[tokio::test]
async fn test_committee_registration() {
telemetry_subscribers::init_for_testing();
let mut bridge_keys = vec![];
for _ in 0..=3 {
let (_, kp): (_, BridgeAuthorityKeyPair) = get_key_pair();
bridge_keys.push(kp);
}
let test_cluster = TestClusterWrapperBuilder::new()
.with_bridge_authority_keys(bridge_keys)
.build()
.await;

let bridge = get_bridge(
test_cluster
.inner
.fullnode_handle
.sui_node
.state()
.get_object_store(),
)
.unwrap();

// Member should be empty before end of epoch
assert!(bridge.committee().members.contents.is_empty());
assert_eq!(
test_cluster.inner.swarm.active_validators().count(),
bridge.committee().member_registrations.contents.len()
);

test_cluster
.trigger_reconfiguration_if_not_yet_and_assert_bridge_committee_initialized()
.await;
}

#[tokio::test]
async fn test_bridge_api_compatibility() {
let test_cluster: test_cluster::TestCluster = TestClusterBuilder::new()
.with_protocol_version(BRIDGE_ENABLE_PROTOCOL_VERSION.into())
.build()
.await;

test_cluster.trigger_reconfiguration().await;
let client = test_cluster.rpc_client();
client.get_latest_bridge().await.unwrap();
// TODO: assert fields in summary

client
.get_bridge_object_initial_shared_version()
.await
.unwrap();
}

pub(crate) async fn deposit_native_eth_to_sol_contract(
signer: &EthSigner,
contract_address: EthAddress,
Expand Down
Loading

0 comments on commit 31b15dd

Please sign in to comment.