Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bridge Pool CLI tests #865

Merged
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
bcf56cd
Merge branch 'eth-bridge-integration' into bat/ethbridge/test-bridge-…
batconjurer Nov 8, 2022
7bca9b5
[fix]: Renaming xan to nam
batconjurer Nov 8, 2022
e18f899
Merge branch 'bat/ethbridge/test-bridge-pool-wasms' into bat/ethbridg…
batconjurer Nov 10, 2022
bb98133
[fix]: Fixed the wasm for adding transfers to the bridge pool
batconjurer Nov 29, 2022
3ac4de1
[feat]: Added e2e test verifying that transfers can be added to the e…
batconjurer Nov 30, 2022
becad12
[feat]: Added type alias for byte vector in merkle storage
batconjurer Nov 30, 2022
818da88
[feat]: Changed the bytes passed into merkle proof to be references
batconjurer Dec 1, 2022
4f51d4b
Ensure pending events require at least the protocol specified min con…
james-chf Dec 1, 2022
53be7c5
Add a basic test for min confirmations
james-chf Dec 1, 2022
b785eca
Expand test to cover transfers to Ethereum also
james-chf Dec 1, 2022
d34a23f
Test custom confirmations may be used
james-chf Dec 1, 2022
f6994e5
[chore]: merged in fixes to merkle proofs
batconjurer Dec 1, 2022
d4bc962
[fix]: Merge in the part of PR #813 to fix the tx_unbond.wasm tests
batconjurer Dec 1, 2022
31cf7b4
Merge branch 'bat/ethbridge/proof-values-ref' into bat/ethbridge/test…
batconjurer Dec 1, 2022
ab12224
[feat]: E2E tests for the bridge pool are now working
batconjurer Dec 2, 2022
0ac0bc1
Update shared/src/ledger/storage/merkle_tree.rs
batconjurer Dec 6, 2022
8844903
Update apps/src/lib/node/ledger/ethereum_node/events.rs
james-chf Dec 6, 2022
2af693a
Revert "Update shared/src/ledger/storage/merkle_tree.rs"
batconjurer Dec 6, 2022
b3c4ff7
Merge pull request #855 from anoma/james/ethbridge/min-confirmations-…
james-chf Dec 6, 2022
ca0cb2d
Merge pull request #851 from anoma/bat/ethbridge/proof-values-ref
batconjurer Dec 6, 2022
fe3401d
Update apps/src/lib/client/eth_bridge_pool.rs
batconjurer Dec 6, 2022
1e9dcf5
Update tests/src/e2e/eth_bridge_tests.rs
batconjurer Dec 6, 2022
0a917fc
[fix]: Fixed the wasm for adding transfers to the bridge pool
batconjurer Nov 29, 2022
92921b8
[feat]: Added type alias for byte vector in merkle storage
batconjurer Nov 30, 2022
7eb1d28
[feat]: E2E tests for the bridge pool are now working
batconjurer Dec 2, 2022
72e22c7
Update apps/src/lib/client/eth_bridge_pool.rs
batconjurer Dec 6, 2022
f94015b
Update tests/src/e2e/eth_bridge_tests.rs
batconjurer Dec 6, 2022
f34f926
Merge branch 'bat/ethbridge/test-bridge-pool-cli' of github.com:anoma…
batconjurer Dec 6, 2022
685d50b
[feat]: Added e2e test to CI workflow
batconjurer Dec 6, 2022
e95d71a
[feat]: Birdge pool query now returns only a json payload
batconjurer Dec 6, 2022
db48ac9
[fix]: Removed DAI address as receiver address from e2e test
batconjurer Dec 6, 2022
fd6a396
Update wasm/wasm_source/src/tx_bridge_pool.rs
batconjurer Dec 7, 2022
80c1897
Update wasm/wasm_source/src/tx_bridge_pool.rs
batconjurer Dec 7, 2022
7c77d5e
Update wasm/wasm_source/src/tx_bridge_pool.rs
batconjurer Dec 7, 2022
e02f00c
[fix]: reverted wasm/checksums.json
batconjurer Dec 7, 2022
d681d44
[fix]: Formatting
batconjurer Dec 7, 2022
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
17 changes: 14 additions & 3 deletions apps/src/lib/client/eth_bridge_pool.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::collections::HashMap;

use borsh::BorshSerialize;
use namada::ledger::queries::RPC;
use namada::proto::Tx;
use namada::types::eth_abi::Encode;
use namada::types::eth_bridge_pool::{
GasFee, PendingTransfer, TransferToEthereum,
};
Expand Down Expand Up @@ -67,11 +70,19 @@ pub async fn construct_bridge_pool_proof(args: args::BridgePoolProof) {
/// Prints out a json payload.
pub async fn query_bridge_pool(args: args::Query) {
let client = HttpClient::new(args.ledger_address).unwrap();
let response = RPC
let response: Vec<PendingTransfer> = RPC
.shell()
.read_ethereum_bridge_pool(&client)
.await
.unwrap();

println!("{:#?}", serde_json::to_string_pretty(&response));
let pool_contents: HashMap<String, PendingTransfer> = response
.into_iter()
.map(|transfer| (transfer.keccak256().to_string(), transfer))
.collect();
if pool_contents.is_empty() {
println!("Bridge pool is empty.");
batconjurer marked this conversation as resolved.
Show resolved Hide resolved
} else {
println!("Bridge pool contents: ");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
println!("Bridge pool contents: ");
print!("Bridge pool contents: ");

nit: maybe this is the desired output here? Bridge pool contents: { ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This I'm not sure about until I see it on the screen. Will get back to it when I have time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It made the whole thing a json payload, which is what I really wanted anyway.

}
println!("{}", serde_json::to_string_pretty(&pool_contents).unwrap());
batconjurer marked this conversation as resolved.
Show resolved Hide resolved
}
22 changes: 19 additions & 3 deletions apps/src/lib/config/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ use std::path::Path;

use borsh::{BorshDeserialize, BorshSerialize};
use derivative::Derivative;
use namada::ledger::eth_bridge::parameters::EthereumBridgeConfig;
use namada::ledger::eth_bridge::parameters::{
Contracts, EthereumBridgeConfig, UpgradeableContract,
};
use namada::ledger::governance::parameters::GovParams;
use namada::ledger::parameters::Parameters;
use namada::ledger::pos::{GenesisValidator, PosParams};
use namada::types::address::Address;
use namada::types::address::{wnam, Address};
#[cfg(not(feature = "dev"))]
use namada::types::chain::ChainId;
use namada::types::ethereum_events::EthAddress;
use namada::types::key::dkg_session_keys::DkgPublicKey;
use namada::types::key::*;
use namada::types::time::DateTimeUtc;
Expand Down Expand Up @@ -881,7 +884,20 @@ pub fn genesis() -> Genesis {
parameters,
pos_params: PosParams::default(),
gov_params: GovParams::default(),
ethereum_bridge_params: None,
ethereum_bridge_params: Some(EthereumBridgeConfig {
min_confirmations: Default::default(),
contracts: Contracts {
native_erc20: wnam(),
bridge: UpgradeableContract {
address: EthAddress([0; 20]),
version: Default::default(),
},
governance: UpgradeableContract {
address: EthAddress([1; 20]),
version: Default::default(),
},
},
}),
}
}

Expand Down
1 change: 1 addition & 0 deletions apps/src/lib/node/ledger/shell/init_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ where
genesis.gov_params.init_storage(&mut self.storage);
// configure the Ethereum bridge if the configuration is set.
if let Some(config) = genesis.ethereum_bridge_params {
tracing::debug!("Initializing Ethereum bridge storage.");
config.init_storage(&mut self.storage);
}

Expand Down
10 changes: 0 additions & 10 deletions proof_of_stake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,8 +1046,6 @@ pub enum BondError<Address: Display + Debug> {
InactiveValidator(Address),
#[error("Voting power overflow: {0}")]
VotingPowerOverflow(TryFromIntError),
#[error("Given zero amount to bond")]
ZeroAmount,
}

#[allow(missing_docs)]
Expand All @@ -1065,8 +1063,6 @@ pub enum UnbondError<Address: Display + Debug, TokenAmount: Display + Debug> {
ValidatorHasNoVotingPower(Address),
#[error("Voting power overflow: {0}")]
VotingPowerOverflow(TryFromIntError),
#[error("Given zero amount to unbond")]
ZeroAmount,
}

#[allow(missing_docs)]
Expand Down Expand Up @@ -1611,9 +1607,6 @@ where
+ BorshSerialize
+ BorshSchema,
{
if amount == TokenAmount::default() {
return Err(BondError::ZeroAmount);
}
// Check the validator state
match validator_state {
None => {
Expand Down Expand Up @@ -1791,9 +1784,6 @@ where
+ BorshSerialize
+ BorshSchema,
{
if amount == TokenAmount::default() {
return Err(UnbondError::ZeroAmount);
}
// We can unbond tokens that are bonded for a future epoch (not yet
// active), hence we check the total at the pipeline offset
let unbondable_amount = bond
Expand Down
13 changes: 6 additions & 7 deletions shared/src/ledger/queries/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,7 @@ where
let proof = if request.prove {
let proof = ctx
.storage
.get_existence_proof(
&storage_key,
value.clone(),
request.height,
)
.get_existence_proof(&storage_key, &value, request.height)
.into_storage_result()?;
Some(proof)
} else {
Expand Down Expand Up @@ -309,7 +305,7 @@ where
for PrefixValue { key, value } in &data {
let mut proof = ctx
.storage
.get_existence_proof(key, value.clone(), request.height)
.get_existence_proof(key, value, request.height)
.into_storage_result()?;
ops.append(&mut proof.ops);
}
Expand Down Expand Up @@ -477,7 +473,10 @@ where
)));
}
// get the membership proof
match tree.get_sub_tree_existence_proof(&keys, values) {
match tree.get_sub_tree_existence_proof(
&keys,
values.iter().map(|v| v.as_slice()).collect(),
) {
Ok(BridgePool(proof)) => {
let data = EncodeCell::new(&RelayProof {
// TODO: use actual validators
Expand Down
6 changes: 3 additions & 3 deletions shared/src/ledger/storage/merkle_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub enum Error {
type Result<T> = std::result::Result<T, Error>;

/// Type alias for bytes to be put into the Merkle storage
pub(super) type StorageBytes = Vec<u8>;
pub(super) type StorageBytes<'a> = &'a [u8];

/// Type aliases for the different merkle trees and backing stores
pub type SmtStore = DefaultStore<SmtHash, Hash, 32>;
Expand Down Expand Up @@ -733,7 +733,7 @@ mod test {
let proof = match tree
.get_sub_tree_existence_proof(
std::array::from_ref(&ibc_key),
vec![ibc_val.clone()],
vec![&ibc_val],
)
.unwrap()
{
Expand Down Expand Up @@ -792,7 +792,7 @@ mod test {
let proof = match tree
.get_sub_tree_existence_proof(
std::array::from_ref(&pos_key),
vec![pos_val.clone()],
vec![&pos_val],
)
.unwrap()
{
Expand Down
4 changes: 2 additions & 2 deletions shared/src/ledger/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use crate::ledger::pos::namada_proof_of_stake::PosBase;
use crate::ledger::pos::types::WeightedValidator;
use crate::ledger::pos::PosParams;
use crate::ledger::storage::merkle_tree::{
Error as MerkleTreeError, MerkleRoot,
Error as MerkleTreeError, MerkleRoot, StorageBytes,
};
pub use crate::ledger::storage::merkle_tree::{
MerkleTree, MerkleTreeStoresRead, MerkleTreeStoresWrite, StoreRef,
Expand Down Expand Up @@ -619,7 +619,7 @@ where
pub fn get_existence_proof(
&self,
key: &Key,
value: Vec<u8>,
value: StorageBytes,
height: BlockHeight,
) -> Result<Proof> {
if height >= self.get_block_height().0 {
Expand Down
18 changes: 10 additions & 8 deletions shared/src/ledger/storage/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub trait SubTreeWrite {
fn subtree_update(
&mut self,
key: &Key,
value: &[u8],
value: StorageBytes,
) -> Result<Hash, Error>;
/// Delete a key from the sub-tree
fn subtree_delete(&mut self, key: &Key) -> Result<Hash, Error>;
Expand Down Expand Up @@ -68,7 +68,7 @@ impl<'a, H: StorageHasher + Default> SubTreeRead for &'a Smt<H> {
Ics23Proof::Exist(ep) => Ok(CommitmentProof {
proof: Some(Ics23Proof::Exist(ExistenceProof {
key: key.to_string().as_bytes().to_vec(),
value,
value: value.to_vec(),
leaf: Some(ics23_specs::leaf_spec::<H>()),
..ep
})),
Expand All @@ -84,7 +84,7 @@ impl<'a, H: StorageHasher + Default> SubTreeWrite for &'a mut Smt<H> {
fn subtree_update(
&mut self,
key: &Key,
value: &[u8],
value: StorageBytes,
) -> Result<Hash, Error> {
let value = H::hash(value);
self.update(H::hash(key.to_string()).into(), value.into())
Expand Down Expand Up @@ -139,7 +139,7 @@ impl<'a, H: StorageHasher + Default> SubTreeWrite for &'a mut Amt<H> {
fn subtree_update(
&mut self,
key: &Key,
value: &[u8],
value: StorageBytes,
) -> Result<Hash, Error> {
let key = StringKey::try_from_bytes(key.to_string().as_bytes())?;
let value = TreeBytes::from(value.as_ref().to_owned());
Expand Down Expand Up @@ -170,9 +170,7 @@ impl<'a> SubTreeRead for &'a BridgePoolTree {
) -> Result<MembershipProof, Error> {
let values = values
.iter()
.filter_map(|val| {
PendingTransfer::try_from_slice(val.as_slice()).ok()
})
.filter_map(|val| PendingTransfer::try_from_slice(val).ok())
.collect();
self.get_membership_proof(values)
.map(Into::into)
Expand All @@ -181,7 +179,11 @@ impl<'a> SubTreeRead for &'a BridgePoolTree {
}

impl<'a> SubTreeWrite for &'a mut BridgePoolTree {
fn subtree_update(&mut self, key: &Key, _: &[u8]) -> Result<Hash, Error> {
fn subtree_update(
&mut self,
key: &Key,
_: StorageBytes,
) -> Result<Hash, Error> {
self.insert_key(key)
.map_err(|err| Error::MerkleTree(err.to_string()))
}
Expand Down
10 changes: 9 additions & 1 deletion shared/src/types/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl FromStr for Amount {
match rust_decimal::Decimal::from_str(s) {
Ok(decimal) => {
let scale = decimal.scale();
if scale > 6 {
if scale > MAX_DECIMAL_PLACES {
return Err(AmountParseError::ScaleTooLarge(scale));
}
let whole =
Expand Down Expand Up @@ -518,4 +518,12 @@ pub mod testing {
pub fn arb_amount_ceiled(max: u64) -> impl Strategy<Value = Amount> {
(0..=max).prop_map(Amount::from)
}

/// Generate an arbitrary non-zero token amount up to and including given
/// `max` value
pub fn arb_amount_non_zero_ceiled(
max: u64,
) -> impl Strategy<Value = Amount> {
(1..=max).prop_map(Amount::from)
}
}
Loading