Skip to content

Commit

Permalink
Merge branch 'fraccaman/masp-vp-fix' (#1666)
Browse files Browse the repository at this point in the history
* origin/fraccaman/masp-vp-fix:
  e2e: fix test_genesis_validators
  e2e/masp: fix masp_txs_and_queries
  e2e/masp_incentives: wait for first epoch
  vp/masp: invalid condition, minor logs
  • Loading branch information
Fraccaman committed Jul 7, 2023
2 parents e3ce98d + 053a8f7 commit 3653daf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
21 changes: 14 additions & 7 deletions tests/src/e2e/ledger_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,8 @@ fn masp_txs_and_queries() -> Result<()> {

let validator_one_rpc = get_actor_rpc(&test, &Who::Validator(0));

let _ep1 = epoch_sleep(&test, &validator_one_rpc, 720)?;

let txs_args = vec![
// 2. Attempt to spend 10 BTC at SK(A) to PA(B)
(
Expand Down Expand Up @@ -1113,7 +1115,7 @@ fn masp_incentives() -> Result<()> {
|genesis| {
let parameters = ParametersConfig {
epochs_per_year: epochs_per_year_from_min_duration(
if is_debug_mode() { 240 } else { 60 },
if is_debug_mode() { 340 } else { 85 },
),
min_num_of_blocks: 1,
..genesis.parameters
Expand Down Expand Up @@ -1144,7 +1146,7 @@ fn masp_incentives() -> Result<()> {
let validator_one_rpc = get_actor_rpc(&test, &Who::Validator(0));

// Wait till epoch boundary
let ep0 = get_epoch(&test, &validator_one_rpc)?;
let ep0 = epoch_sleep(&test, &validator_one_rpc, 720)?;

// Send 20 BTC from Albert to PA(A)
let mut client = run!(
Expand Down Expand Up @@ -1524,7 +1526,7 @@ fn masp_incentives() -> Result<()> {
client.exp_string("No shielded eth balance found")?;
client.assert_success();

let mut ep = get_epoch(&test, &validator_one_rpc)?;
// let mut ep = get_epoch(&test, &validator_one_rpc)?;

// Assert NAM balance at VK(B) is 10*ETH_reward*(ep-epoch_3)
let mut client = run!(
Expand All @@ -1541,15 +1543,15 @@ fn masp_incentives() -> Result<()> {
],
Some(60)
)?;
let amt = (amt10 * masp_rewards[&(eth(), None)]).0 * (ep.0 - ep3.0);
let amt = (amt10 * masp_rewards[&(eth(), None)]).0 * (ep5.0 - ep3.0);
let denominated = DenominatedAmount {
amount: amt,
denom: NATIVE_MAX_DECIMAL_PLACES.into(),
};
client.exp_string(&format!("nam: {}", denominated,))?;
client.assert_success();

ep = get_epoch(&test, &validator_one_rpc)?;
// ep = get_epoch(&test, &validator_one_rpc)?;
// Assert NAM balance at MASP pool is
// 20*BTC_reward*(epoch_5-epoch_0)+10*ETH_reward*(epoch_5-epoch_3)
let mut client = run!(
Expand All @@ -1566,8 +1568,8 @@ fn masp_incentives() -> Result<()> {
],
Some(60)
)?;
let amt = ((amt20 * masp_rewards[&(btc(), None)]).0 * (ep.0 - ep0.0))
+ ((amt10 * masp_rewards[&(eth(), None)]).0 * (ep.0 - ep3.0));
let amt = ((amt20 * masp_rewards[&(btc(), None)]).0 * (ep5.0 - ep0.0))
+ ((amt10 * masp_rewards[&(eth(), None)]).0 * (ep5.0 - ep3.0));
let denominated = DenominatedAmount {
amount: amt,
denom: NATIVE_MAX_DECIMAL_PLACES.into(),
Expand Down Expand Up @@ -4276,6 +4278,11 @@ fn test_genesis_validators() -> Result<()> {
wait_for_wasm_pre_compile(&mut validator_1)?;
wait_for_wasm_pre_compile(&mut non_validator)?;

// Wait for a first block
validator_0.exp_string("Committed block hash")?;
validator_1.exp_string("Committed block hash")?;
non_validator.exp_string("Committed block hash")?;

let bg_validator_0 = validator_0.background();
let bg_validator_1 = validator_1.background();
let _bg_non_validator = non_validator.background();
Expand Down
12 changes: 2 additions & 10 deletions wasm/wasm_source/src/vp_masp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,21 +168,13 @@ fn validate_tx(
shielded_tx.transparent_bundle().ok_or_err_msg(
"Expected transparent outputs in unshielding transaction",
)?;
if transp_bundle.vout.len() != 1 {
debug_log!(
"Transparent output to a transaction from the masp must \
be 1 but is {}",
transp_bundle.vin.len()
);

return reject();
}
let out_length = transp_bundle.vout.len();
if !(1..=4).contains(&out_length) {
debug_log!(
"Transparent output to a transaction to the masp must be \
beteween 1 and 4 but is {}",
transp_bundle.vin.len()
transp_bundle.vout.len()
);

return reject();
Expand Down Expand Up @@ -264,7 +256,7 @@ fn validate_tx(
debug_log!(
"Transparent output to a transaction from the masp \
must be 0 but is {}",
transp_bundle.vin.len()
transp_bundle.vout.len()
);
return reject();
}
Expand Down

0 comments on commit 3653daf

Please sign in to comment.