-
Notifications
You must be signed in to change notification settings - Fork 956
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'mergify/bp/0.44.0/pr-3866' (#3881)
* origin/mergify/bp/0.44.0/pr-3866: Increases timeout on epoch sleep Improves epoch sleeping in ibc tests and renames token variable Changelog #3866 Sped up ibc token test Fixes ibc gas payment test Fixes typos and updates docstring e2e test for ibc token gas payment
- Loading branch information
Showing
12 changed files
with
217 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- Added test for gas payment with an IBC token. | ||
([\#3866](https://github.com/anoma/namada/pull/3866)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,8 +40,8 @@ use setup::constants::*; | |
use sha2::{Digest, Sha256}; | ||
|
||
use crate::e2e::helpers::{ | ||
epochs_per_year_from_min_duration, find_address, find_gaia_address, | ||
get_actor_rpc, get_epoch, get_gaia_gov_address, | ||
epoch_sleep, epochs_per_year_from_min_duration, find_address, | ||
find_gaia_address, get_actor_rpc, get_epoch, get_gaia_gov_address, | ||
}; | ||
use crate::e2e::ledger_tests::{ | ||
start_namada_ledger_node_wait_wasm, write_json_file, | ||
|
@@ -234,6 +234,7 @@ fn ibc_transfers() -> Result<()> { | |
&ibc_denom_on_namada, | ||
50, | ||
ALBERT_KEY, | ||
&[], | ||
)?; | ||
check_balance(&test, AA_VIEWING_KEY, &ibc_denom_on_namada, 50)?; | ||
check_balance(&test, AB_VIEWING_KEY, &ibc_denom_on_namada, 50)?; | ||
|
@@ -479,6 +480,7 @@ fn pgf_over_ibc() -> Result<()> { | |
NAM, | ||
100, | ||
ALBERT_KEY, | ||
&[], | ||
)?; | ||
|
||
// Proposal on Namada | ||
|
@@ -488,8 +490,7 @@ fn pgf_over_ibc() -> Result<()> { | |
let mut epoch = get_epoch(&test, &rpc).unwrap(); | ||
let delegated = epoch + PIPELINE_LEN; | ||
while epoch < delegated { | ||
sleep(5); | ||
epoch = get_epoch(&test, &rpc).unwrap(); | ||
epoch = epoch_sleep(&test, &rpc, 120)?; | ||
} | ||
// funding proposal | ||
let continuous_receiver = find_gaia_address(&test_gaia, GAIA_RELAYER)?; | ||
|
@@ -504,16 +505,14 @@ fn pgf_over_ibc() -> Result<()> { | |
let mut epoch = get_epoch(&test, &rpc).unwrap(); | ||
// Vote | ||
while epoch < start_epoch { | ||
sleep(5); | ||
epoch = get_epoch(&test, &rpc).unwrap(); | ||
epoch = epoch_sleep(&test, &rpc, 120)?; | ||
} | ||
submit_votes(&test)?; | ||
|
||
// wait for the grace | ||
let grace_epoch = start_epoch + 6u64; | ||
while epoch < grace_epoch { | ||
sleep(5); | ||
epoch = get_epoch(&test, &rpc).unwrap(); | ||
epoch = epoch_sleep(&test, &rpc, 120)?; | ||
} | ||
wait_for_packet_relay(&port_id_namada, &channel_id_namada, &test)?; | ||
|
||
|
@@ -526,6 +525,108 @@ fn pgf_over_ibc() -> Result<()> { | |
Ok(()) | ||
} | ||
|
||
// Test fee payment with an ibc token | ||
// | ||
// 1. Submit governance proposal to allow fee payment with the IBC token | ||
// 2. Transfer some IBC tokens from gaia | ||
// 3. Transparent transfer in Namada with ibc token gas payment | ||
#[test] | ||
fn fee_payment_with_ibc_token() -> Result<()> { | ||
const PIPELINE_LEN: u64 = 2; | ||
let update_genesis = | ||
|mut genesis: templates::All<templates::Unvalidated>, base_dir: &_| { | ||
genesis.parameters.parameters.epochs_per_year = | ||
epochs_per_year_from_min_duration(30); | ||
genesis.parameters.ibc_params.default_mint_limit = | ||
Amount::max_signed(); | ||
genesis.parameters.gov_params.min_proposal_grace_epochs = 1; | ||
genesis | ||
.parameters | ||
.ibc_params | ||
.default_per_epoch_throughput_limit = Amount::max_signed(); | ||
// Artificially increase the gas scale to allow for fee payment with | ||
// the limited ibc tokens available | ||
genesis.parameters.parameters.gas_scale = 10_000_000; | ||
setup::set_validators(1, genesis, base_dir, |_| 0, vec![]) | ||
}; | ||
let (ledger, gaia, test, test_gaia) = run_namada_gaia(update_genesis)?; | ||
let _bg_ledger = ledger.background(); | ||
let _bg_gaia = gaia.background(); | ||
|
||
// Proposal on Namada | ||
// Delegate some token | ||
delegate_token(&test)?; | ||
let rpc = get_actor_rpc(&test, Who::Validator(0)); | ||
let mut epoch = get_epoch(&test, &rpc).unwrap(); | ||
let delegated = epoch + PIPELINE_LEN; | ||
while epoch < delegated { | ||
epoch = epoch_sleep(&test, &rpc, 120)?; | ||
} | ||
// ibc gas token proposal on Namada | ||
let start_epoch = propose_gas_token(&test)?; | ||
let mut epoch = get_epoch(&test, &rpc).unwrap(); | ||
// Vote | ||
while epoch < start_epoch { | ||
epoch = epoch_sleep(&test, &rpc, 120)?; | ||
} | ||
submit_votes(&test)?; | ||
|
||
// Create an IBC channel while waiting the grace epoch | ||
setup_hermes(&test, &test_gaia)?; | ||
let (channel_id_namada, channel_id_gaia) = | ||
create_channel_with_hermes(&test, &test_gaia)?; | ||
let port_id_gaia = "transfer".parse().unwrap(); | ||
let port_id_namada = "transfer"; | ||
let ibc_token_on_namada = | ||
format!("{port_id_namada}/{channel_id_namada}/{GAIA_COIN}"); | ||
// Start relaying | ||
let hermes = run_hermes(&test)?; | ||
let _bg_hermes = hermes.background(); | ||
|
||
// wait for the grace | ||
let grace_epoch = start_epoch + 4u64; | ||
while epoch < grace_epoch { | ||
epoch = epoch_sleep(&test, &rpc, 120)?; | ||
} | ||
|
||
// Transfer 250 samoleans from Gaia to Namada | ||
let namada_receiver = find_address(&test, ALBERT_KEY)?.to_string(); | ||
transfer_from_gaia( | ||
&test_gaia, | ||
GAIA_USER, | ||
&namada_receiver, | ||
GAIA_COIN, | ||
250, | ||
&port_id_gaia, | ||
&channel_id_gaia, | ||
None, | ||
None, | ||
)?; | ||
wait_for_packet_relay(&port_id_gaia, &channel_id_gaia, &test)?; | ||
|
||
// Check the token on Namada | ||
check_balance(&test, ALBERT_KEY, &ibc_token_on_namada, 250)?; | ||
check_gaia_balance(&test_gaia, GAIA_USER, GAIA_COIN, 750)?; | ||
|
||
// Transparent transfer in Namada paying gas with samoleans | ||
transfer_on_chain( | ||
&test, | ||
"transparent-transfer", | ||
ALBERT, | ||
CHRISTEL, | ||
NAM, | ||
50, | ||
ALBERT_KEY, | ||
&["--gas-token", &ibc_token_on_namada, "--gas-limit", "250"], | ||
)?; | ||
check_balance(&test, ALBERT, NAM, 1_999_950)?; | ||
check_balance(&test, CHRISTEL, NAM, 2_000_050)?; | ||
check_balance(&test, ALBERT_KEY, &ibc_token_on_namada, 0)?; | ||
check_balance(&test, "validator-0", &ibc_token_on_namada, 250)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
/// IBC token inflation test | ||
/// - Propose the inflation of an IBC token received from Gaia | ||
/// - Shielding transfer of the token from Gaia | ||
|
@@ -560,20 +661,14 @@ fn ibc_token_inflation() -> Result<()> { | |
let mut epoch = get_epoch(&test, &rpc).unwrap(); | ||
let delegated = epoch + PIPELINE_LEN; | ||
while epoch < delegated { | ||
sleep(10); | ||
#[allow(clippy::disallowed_methods)] | ||
let new_epoch = get_epoch(&test, &rpc).unwrap_or_default(); | ||
epoch = new_epoch; | ||
epoch = epoch_sleep(&test, &rpc, 120)?; | ||
} | ||
// inflation proposal on Namada | ||
let start_epoch = propose_inflation(&test)?; | ||
let mut epoch = get_epoch(&test, &rpc).unwrap(); | ||
// Vote | ||
while epoch < start_epoch { | ||
sleep(10); | ||
#[allow(clippy::disallowed_methods)] | ||
let new_epoch = get_epoch(&test, &rpc).unwrap_or_default(); | ||
epoch = new_epoch; | ||
epoch = epoch_sleep(&test, &rpc, 120)?; | ||
} | ||
submit_votes(&test)?; | ||
|
||
|
@@ -590,8 +685,7 @@ fn ibc_token_inflation() -> Result<()> { | |
// wait for the grace | ||
let grace_epoch = start_epoch + 6u64; | ||
while epoch < grace_epoch { | ||
sleep(5); | ||
epoch = get_epoch(&test, &rpc).unwrap(); | ||
epoch = epoch_sleep(&test, &rpc, 120)?; | ||
} | ||
|
||
// Check the target balance is zero before the inflation | ||
|
@@ -622,10 +716,7 @@ fn ibc_token_inflation() -> Result<()> { | |
let mut epoch = get_epoch(&test, &rpc).unwrap(); | ||
let new_epoch = epoch + MASP_EPOCH_MULTIPLIER; | ||
while epoch < new_epoch { | ||
sleep(10); | ||
#[allow(clippy::disallowed_methods)] | ||
let new_epoch = get_epoch(&test, &rpc).unwrap_or_default(); | ||
epoch = new_epoch; | ||
epoch = epoch_sleep(&test, &rpc, 120)?; | ||
} | ||
|
||
// Check balances | ||
|
@@ -726,8 +817,7 @@ fn ibc_rate_limit() -> Result<()> { | |
let mut epoch = get_epoch(&test, &rpc).unwrap(); | ||
let next_epoch = epoch.next(); | ||
while epoch <= next_epoch { | ||
sleep(5); | ||
epoch = get_epoch(&test, &rpc).unwrap(); | ||
epoch = epoch_sleep(&test, &rpc, 120)?; | ||
} | ||
|
||
// Transfer 1 NAM from Namada to Gaia | ||
|
@@ -770,8 +860,7 @@ fn ibc_rate_limit() -> Result<()> { | |
let mut epoch = get_epoch(&test, &rpc).unwrap(); | ||
let next_epoch = epoch.next(); | ||
while epoch <= next_epoch { | ||
sleep(5); | ||
epoch = get_epoch(&test, &rpc).unwrap(); | ||
epoch = epoch_sleep(&test, &rpc, 120)?; | ||
} | ||
|
||
// Transfer 1 NAM from Namada to Gaia will succeed in the new epoch | ||
|
@@ -1052,10 +1141,11 @@ fn transfer_on_chain( | |
token: impl AsRef<str>, | ||
amount: u64, | ||
signer: impl AsRef<str>, | ||
extra_args: &[&str], | ||
) -> Result<()> { | ||
let rpc = get_actor_rpc(test, Who::Validator(0)); | ||
let amount = amount.to_string(); | ||
let tx_args = apply_use_device(vec![ | ||
let mut tx_args = apply_use_device(vec![ | ||
kind.as_ref(), | ||
"--source", | ||
sender.as_ref(), | ||
|
@@ -1070,6 +1160,7 @@ fn transfer_on_chain( | |
"--node", | ||
&rpc, | ||
]); | ||
tx_args.extend_from_slice(extra_args); | ||
let mut client = run!(test, Bin::Client, tx_args, Some(120))?; | ||
client.exp_string(TX_APPLIED_SUCCESS)?; | ||
client.assert_success(); | ||
|
@@ -1367,6 +1458,50 @@ fn propose_upgrade_client( | |
Ok(()) | ||
} | ||
|
||
fn propose_gas_token(test: &Test) -> Result<Epoch> { | ||
let albert = find_address(test, ALBERT)?; | ||
let rpc = get_actor_rpc(test, Who::Validator(0)); | ||
let epoch = get_epoch(test, &rpc)?; | ||
let start_epoch = (epoch.0 + 3) / 3 * 3; | ||
let proposal_json = serde_json::json!({ | ||
"proposal": { | ||
"content": { | ||
"title": "IBC token gas", | ||
"authors": "[email protected]", | ||
"discussions-to": "www.github.com/anoma/aip/1", | ||
"created": "2022-03-10T08:54:37Z", | ||
"license": "MIT", | ||
"abstract": "IBC token gas", | ||
"motivation": "IBC token gas", | ||
"details": "IBC token gas", | ||
"requires": "2" | ||
}, | ||
"author": albert, | ||
"voting_start_epoch": start_epoch, | ||
"voting_end_epoch": start_epoch + 3_u64, | ||
"activation_epoch": start_epoch + 4_u64, | ||
}, | ||
"data": TestWasms::TxProposalTokenGas.read_bytes() | ||
}); | ||
|
||
let proposal_json_path = test.test_dir.path().join("proposal.json"); | ||
write_json_file(proposal_json_path.as_path(), proposal_json); | ||
|
||
let submit_proposal_args = apply_use_device(vec![ | ||
"init-proposal", | ||
"--data-path", | ||
proposal_json_path.to_str().unwrap(), | ||
"--gas-limit", | ||
"10000000", | ||
"--node", | ||
&rpc, | ||
]); | ||
let mut client = run!(test, Bin::Client, submit_proposal_args, Some(100))?; | ||
client.exp_string(TX_APPLIED_SUCCESS)?; | ||
client.assert_success(); | ||
Ok(start_epoch.into()) | ||
} | ||
|
||
fn wait_for_pass(test: &Test) -> Result<()> { | ||
let args = ["query", "gov", "proposal", "1"]; | ||
for _ in 0..10 { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.