Skip to content

Commit

Permalink
wip: new bridge pool tests ( S Q U A S H M E P L S )
Browse files Browse the repository at this point in the history
  • Loading branch information
sug0 committed Aug 2, 2023
1 parent 312a5cf commit 6e909a2
Showing 1 changed file with 59 additions and 2 deletions.
61 changes: 59 additions & 2 deletions shared/src/ledger/native_vp/ethereum_bridge/bridge_pool_vp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,8 @@ mod test_bridge_pool_vp {

/// A set of balances for an address
struct Balance {
/// The address of the Ethereum asset.
asset: EthAddress,
/// NUT or ERC20 Ethereum asset kind.
kind: TransferToEthereumKind,
/// The owner of the ERC20 assets.
Expand All @@ -533,6 +535,7 @@ mod test_bridge_pool_vp {
fn new(kind: TransferToEthereumKind, address: Address) -> Self {
Self {
kind,
asset: ASSET,
owner: address,
gas: 0.into(),
token: 0.into(),
Expand Down Expand Up @@ -655,8 +658,12 @@ mod test_bridge_pool_vp {
// get the balance keys
let token_key = balance_key(
&match balance.kind {
TransferToEthereumKind::Erc20 => wrapped_erc20s::token(&ASSET),
TransferToEthereumKind::Nut => wrapped_erc20s::nut(&ASSET),
TransferToEthereumKind::Erc20 => {
wrapped_erc20s::token(&balance.asset)
}
TransferToEthereumKind::Nut => {
wrapped_erc20s::nut(&balance.asset)
}
},
&balance.owner,
);
Expand Down Expand Up @@ -791,6 +798,7 @@ mod test_bridge_pool_vp {
let mut new_keys_changed = update_balances(
&mut wl_storage.write_log,
Balance {
asset: transfer.transfer.asset,
kind: TransferToEthereumKind::Erc20,
owner: bertha_address(),
gas: BERTHA_WEALTH.into(),
Expand All @@ -805,6 +813,7 @@ mod test_bridge_pool_vp {
let mut new_keys_changed = update_balances(
&mut wl_storage.write_log,
Balance {
asset: transfer.transfer.asset,
kind: TransferToEthereumKind::Erc20,
owner: BRIDGE_POOL_ADDRESS,
gas: ESCROWED_AMOUNT.into(),
Expand Down Expand Up @@ -1132,6 +1141,7 @@ mod test_bridge_pool_vp {
let mut new_keys_changed = update_balances(
&mut wl_storage.write_log,
Balance {
asset: ASSET,
kind: TransferToEthereumKind::Erc20,
owner: bertha_address(),
gas: BERTHA_WEALTH.into(),
Expand All @@ -1146,6 +1156,7 @@ mod test_bridge_pool_vp {
let mut new_keys_changed = update_balances(
&mut wl_storage.write_log,
Balance {
asset: ASSET,
kind: TransferToEthereumKind::Erc20,
owner: BRIDGE_POOL_ADDRESS,
gas: ESCROWED_AMOUNT.into(),
Expand Down Expand Up @@ -1569,6 +1580,7 @@ mod test_bridge_pool_vp {
&mut wl_storage.write_log,
Balance {
kind,
asset: ASSET,
owner: daewon_address(),
gas: DAEWONS_GAS.into(),
token: DAES_NUTS.into(),
Expand All @@ -1583,6 +1595,7 @@ mod test_bridge_pool_vp {
&mut wl_storage.write_log,
Balance {
kind,
asset: ASSET,
owner: BRIDGE_POOL_ADDRESS,
gas: ESCROWED_AMOUNT.into(),
token: ESCROWED_NUTS.into(),
Expand Down Expand Up @@ -1628,4 +1641,48 @@ mod test_bridge_pool_vp {
fn test_escrowing_nuts_happy_flow() {
test_nut_aux(TransferToEthereumKind::Nut, Expect::True)
}

/// Test that the Bridge pool VP rejects a wNAM NUT transfer.
#[test]
fn test_bridge_pool_vp_rejects_wnam_nut() {
assert_bridge_pool(
SignedAmount::Negative(GAS_FEE.into()),
SignedAmount::Positive(GAS_FEE.into()),
SignedAmount::Negative(TOKENS.into()),
SignedAmount::Positive(TOKENS.into()),
|transfer, log| {
transfer.transfer.kind = TransferToEthereumKind::Nut;
transfer.transfer.asset = wnam();
log.write(
&get_pending_key(transfer),
transfer.try_to_vec().unwrap(),
)
.unwrap();
BTreeSet::from([get_pending_key(transfer)])
},
Expect::False,
);
}

/// Test that the Bridge pool VP accepts a wNAM ERC20 transfer.
#[test]
fn test_bridge_pool_vp_accepts_wnam_erc20() {
assert_bridge_pool(
SignedAmount::Negative(GAS_FEE.into()),
SignedAmount::Positive(GAS_FEE.into()),
SignedAmount::Negative(TOKENS.into()),
SignedAmount::Positive(TOKENS.into()),
|transfer, log| {
transfer.transfer.kind = TransferToEthereumKind::Erc20;
transfer.transfer.asset = wnam();
log.write(
&get_pending_key(transfer),
transfer.try_to_vec().unwrap(),
)
.unwrap();
BTreeSet::from([get_pending_key(transfer)])
},
Expect::True,
);
}
}

0 comments on commit 6e909a2

Please sign in to comment.