Skip to content

Commit

Permalink
feat(int-on-eos): <- adds test for prev block submissions
Browse files Browse the repository at this point in the history
  • Loading branch information
gskapka committed Jan 31, 2024
1 parent 324810e commit a6a4879
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 4 deletions.
112 changes: 108 additions & 4 deletions v2_bridges/int_on_eos/src/eos/submit_eos_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,16 @@ mod tests {

use common::test_utils::get_test_database;
use common_chain_ids::{EosChainId, EthChainId};
use common_eos::{initialize_eos_core_inner, EosPrivateKey, ProcessedGlobalSequences};
use common_eos::{initialize_eos_core_inner, EosPrivateKey, EosSubmissionMaterial, ProcessedGlobalSequences};
use common_eth::{
initialize_eth_core_with_router_contract_and_return_state,
initialize_eth_core_with_vault_and_router_contracts_and_return_state,
EthDbUtils,
EthDbUtilsExt,
EthState as IntState,
VaultUsingCores,
};
use ethereum_types::Address as EthAddress;
use serde_json::json;

use super::*;
Expand All @@ -105,6 +107,12 @@ mod tests {
get_sample_int_private_key,
get_sample_router_address,
get_sample_vault_address,
multi_incremerkle_submission::{
get_incremekle_update_block,
get_init_block,
get_sample_dictionary as get_sample_dictionary_for_incremerkle_test,
get_submission_block,
},
},
};

Expand Down Expand Up @@ -290,9 +298,6 @@ mod tests {
let processed_glob_sequences_before = ProcessedGlobalSequences::get_from_db(&db).unwrap();
assert!(processed_glob_sequences_before.is_empty());

use simple_logger;
simple_logger::init().unwrap();

// NOTE: Submit the block with the peg in in it...
let output = EosOutput::from_str(
&submit_eos_block_to_core(&db, &get_sample_eos_submission_material_string_2()).unwrap(),
Expand Down Expand Up @@ -348,4 +353,103 @@ mod tests {
let processed_glob_sequences_after = ProcessedGlobalSequences::get_from_db(&db).unwrap();
assert!(processed_glob_sequences_after.contains(&294821926));
}

#[test]
fn should_submit_eos_material_with_proof_tied_to_block_behind_chain_tip() {
let db = get_test_database();
let router_address = get_sample_router_address();

// NOTE: Initialize the EOS mainnet core...
let eos_chain_id = "aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906";
let maybe_eos_account_name = Some("effecttokens");
let maybe_eos_token_symbol = None;
let eos_init_block = get_init_block();
let eos_init_block_num = 351736970;
initialize_eos_core_inner(
&db,
eos_chain_id,
maybe_eos_account_name,
maybe_eos_token_symbol,
&eos_init_block,
true,
)
.unwrap();

// NOTE: Overwrite the EOS private key since it's generated randomly above...
let eos_pk = get_sample_eos_private_key();
eos_pk.write_to_db(&db).unwrap();
assert_eq!(EosPrivateKey::get_from_db(&db).unwrap(), eos_pk);

// NOTE: Initialize the INT side of the core...
let int_confirmations = 0;
let int_gas_price = 20_000_000_000;
let contiguous_int_block_json_strs = get_contiguous_int_block_json_strs();
let int_init_block = contiguous_int_block_json_strs[0].clone();
initialize_eth_core_with_router_contract_and_return_state(
&int_init_block,
&EthChainId::Ropsten,
int_gas_price,
int_confirmations,
IntState::init(&db),
&router_address,
false,
)
.unwrap();

// NOTE: Overwrite the INT address & private key since it's generated randomly above...
let int_address = get_sample_int_address();
let int_private_key = get_sample_int_private_key();
let int_db_utils = EthDbUtils::new(&db);
int_db_utils
.put_eth_address_in_db(&int_db_utils.get_eth_address_key(), &int_address)
.unwrap();
int_db_utils.put_eth_private_key_in_db(&int_private_key).unwrap();
assert_eq!(int_db_utils.get_public_eth_address_from_db().unwrap(), int_address);
assert_eq!(int_db_utils.get_eth_private_key_from_db().unwrap(), int_private_key);

// NOTE: Add a vault address for ETH required for tx signing output
int_db_utils
.put_int_on_eos_smart_contract_address_in_db(&EthAddress::random())
.unwrap();

// NOTE: Add the token dictionary to the db...
let dictionary = get_sample_dictionary_for_incremerkle_test();
dictionary.save_to_db(&db).unwrap();

// NOTE: Assert that there are no processed global sequences in the db...
let processed_glob_sequences_before = ProcessedGlobalSequences::get_from_db(&db).unwrap();
assert!(processed_glob_sequences_before.is_empty());

let mut incremerkles = Incremerkles::get_from_db(&common_eos::EosDbUtils::new(&db)).unwrap();
assert_eq!(incremerkles.len(), 1);
assert_eq!(incremerkles.latest_block_num(), eos_init_block_num);

// NOTE: Now lets update the incremerkle...
let incremerkle_update_block = get_incremekle_update_block();
let incremerkle_update_block_num = EosSubmissionMaterial::from_str(&incremerkle_update_block)
.unwrap()
.block_num;
submit_eos_block_to_core(&db, &incremerkle_update_block).unwrap();

incremerkles = Incremerkles::get_from_db(&common_eos::EosDbUtils::new(&db)).unwrap();
assert_eq!(incremerkles.len(), 2);
assert_eq!(incremerkles.latest_block_num(), incremerkle_update_block_num);

let submission_block_json = get_submission_block();
let submission_block_num = EosSubmissionMaterial::from_str(&submission_block_json)
.unwrap()
.block_num;
assert_eq!(submission_block_num, 351737739);

// NOTE: Let's assert that the core's latest block number is indeed _past_ the submission
// material block num
let latest_block_num = incremerkles.latest_block_num();
assert_eq!(latest_block_num, 351738099);
assert!(latest_block_num > submission_block_num);

// NOTE: Now we can submit the block with the peg in in it...
let output = EosOutput::from_str(&submit_eos_block_to_core(&db, &submission_block_json).unwrap()).unwrap();
// NOTE: Asserting a tx is outputted successfully is sufficient for this test.
assert_eq!(output.int_signed_transactions.len(), 1);
}
}
4 changes: 4 additions & 0 deletions v2_bridges/int_on_eos/src/test_utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#![cfg(test)]

#[cfg(feature = "non-validating")]
pub(crate) mod multi_incremerkle_submission;

use std::fs::read_to_string;

use common::{
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#![cfg(test)]
use std::fs::read_to_string;

use common::dictionaries::eos_eth::{
EosEthTokenDictionary,
EosEthTokenDictionaryEntry,
EosEthTokenDictionaryEntryJson,
};

pub fn get_init_block() -> String {
read_to_string("src/test_utils/multi_incremerkle_submission/init-block.json").unwrap()
}

pub fn get_submission_block() -> String {
read_to_string("src/test_utils/multi_incremerkle_submission/submission-material.json").unwrap()
}

pub fn get_incremekle_update_block() -> String {
read_to_string("src/test_utils/multi_incremerkle_submission/incremerkle-update-block.json").unwrap()
}

pub fn get_sample_dictionary() -> EosEthTokenDictionary {
EosEthTokenDictionary::new(vec![EosEthTokenDictionaryEntry::from_json(
&EosEthTokenDictionaryEntryJson {
eth_token_decimals: 18,
eos_token_decimals: 4,
eth_symbol: "PWOMBAT".to_string(),
eos_symbol: "PWOMBAT".to_string(),
eth_address: "0xb048a1f2d0c839002ee7f7bdc2049c2142f264d6".to_string(),
eos_address: "wmbt.ptokens".to_string(),
eth_fee_basis_points: None,
eos_fee_basis_points: None,
accrued_fees: None,
last_withdrawal: None,
},
)
.unwrap()])
}

Large diffs are not rendered by default.

0 comments on commit a6a4879

Please sign in to comment.