Skip to content

Commit

Permalink
Fixes integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grarco committed May 28, 2024
1 parent 220cbe1 commit 8cd7e79
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 40 deletions.
15 changes: 15 additions & 0 deletions crates/node/src/shell/testing/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,21 @@ impl MockNode {
.0
}

pub fn next_masp_epoch(&mut self) -> Epoch {
let masp_epoch_multiplier =
namada::parameters::read_masp_epoch_multiplier_parameter(
&self.shell.lock().unwrap().state,
)
.unwrap();
let mut epoch = Epoch::default();

for _ in 0..masp_epoch_multiplier {
epoch = self.next_epoch();
}

epoch
}

pub fn native_token(&self) -> Address {
let locked = self.shell.lock().unwrap();
locked.state.get_native_token().unwrap()
Expand Down
80 changes: 40 additions & 40 deletions crates/tests/src/integration/masp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn masp_incentives() -> Result<()> {
// not invalidated.
let (mut node, _services) = setup::setup()?;
// Wait till epoch boundary
node.next_epoch();
node.next_masp_epoch();
// Send 1 BTC from Albert to PA
run(
&node,
Expand Down Expand Up @@ -112,7 +112,7 @@ fn masp_incentives() -> Result<()> {
assert!(captured.contains("nam: 0"));

// Wait till epoch boundary
node.next_epoch();
node.next_masp_epoch();

// sync the shielded context
run(
Expand Down Expand Up @@ -159,7 +159,7 @@ fn masp_incentives() -> Result<()> {
});

assert!(captured.result.is_ok());
assert!(captured.contains("nam: 0.031"));
assert!(captured.contains("nam: 0.063"));

// Assert NAM balance at MASP pool is exclusively the
// rewards from the shielded BTC
Expand All @@ -179,10 +179,10 @@ fn masp_incentives() -> Result<()> {
)
});
assert!(captured.result.is_ok());
assert!(captured.contains("nam: 0.031"));
assert!(captured.contains("nam: 0.063"));

// Wait till epoch boundary
node.next_epoch();
node.next_masp_epoch();

// sync the shielded context
run(
Expand Down Expand Up @@ -229,7 +229,7 @@ fn masp_incentives() -> Result<()> {
)
});
assert!(captured.result.is_ok());
assert!(captured.contains("nam: 0.09292"));
assert!(captured.contains("nam: 0.18887"));

// Assert NAM balance at MASP pool is exclusively the
// rewards from the shielded BTC
Expand All @@ -249,10 +249,10 @@ fn masp_incentives() -> Result<()> {
)
});
assert!(captured.result.is_ok());
assert!(captured.contains("nam: 0.09331"));
assert!(captured.contains("nam: 0.18963"));

// Wait till epoch boundary
node.next_epoch();
node.next_masp_epoch();

// Send 0.001 ETH from Albert to PA(B)
run(
Expand Down Expand Up @@ -321,7 +321,7 @@ fn masp_incentives() -> Result<()> {
assert!(captured.contains("nam: 0"));

// Wait till epoch boundary
node.next_epoch();
node.next_masp_epoch();

// sync the shielded context
run(
Expand Down Expand Up @@ -368,7 +368,7 @@ fn masp_incentives() -> Result<()> {
)
});
assert!(captured.result.is_ok());
assert!(captured.contains("nam: 0.362747"));
assert!(captured.contains("nam: 0.725514"));

// Assert NAM balance at MASP pool is an accumulation of
// rewards from both the shielded BTC and shielded ETH
Expand All @@ -388,10 +388,10 @@ fn masp_incentives() -> Result<()> {
)
});
assert!(captured.result.is_ok());
assert!(captured.contains("nam: 0.674354"));
assert!(captured.contains("nam: 1.358764"));

// Wait till epoch boundary
node.next_epoch();
node.next_masp_epoch();
// Send 0.001 ETH from SK(B) to Christel
run(
&node,
Expand Down Expand Up @@ -441,7 +441,7 @@ fn masp_incentives() -> Result<()> {
assert!(captured.result.is_ok());
assert!(captured.contains("eth: 0"));

node.next_epoch();
node.next_masp_epoch();
// sync the shielded context
run(
&node,
Expand All @@ -468,9 +468,9 @@ fn masp_incentives() -> Result<()> {
)
});
assert!(captured.result.is_ok());
assert!(captured.contains("nam: 0.725855"));
assert!(captured.contains("nam: 1.451732"));

node.next_epoch();
node.next_masp_epoch();
// sync the shielded context
run(
&node,
Expand All @@ -497,10 +497,10 @@ fn masp_incentives() -> Result<()> {
)
});
assert!(captured.result.is_ok());
assert!(captured.contains("nam: 1.595775"));
assert!(captured.contains("nam: 3.219616"));

// Wait till epoch boundary
node.next_epoch();
node.next_masp_epoch();

// Send 1 BTC from SK(A) to Christel
run(
Expand Down Expand Up @@ -568,7 +568,7 @@ fn masp_incentives() -> Result<()> {
)
});
assert!(captured.result.is_ok());
assert!(captured.contains("nam: 1.113911"));
assert!(captured.contains("nam: 2.268662"));

// Assert NAM balance at MASP pool is
// the accumulation of rewards from the shielded assets (BTC and ETH)
Expand All @@ -588,10 +588,10 @@ fn masp_incentives() -> Result<()> {
)
});
assert!(captured.result.is_ok());
assert!(captured.contains("nam: 1.843775"));
assert!(captured.contains("nam: 3.723616"));

// Wait till epoch boundary
node.next_epoch();
node.next_masp_epoch();
// sync the shielded context
run(
&node,
Expand Down Expand Up @@ -619,7 +619,7 @@ fn masp_incentives() -> Result<()> {
)
});
assert!(captured.result.is_ok());
assert!(captured.contains("nam: 1.113911"));
assert!(captured.contains("nam: 2.268662"));

// Assert NAM balance at VK(B) is the rewards dispensed earlier
// (since VK(A) has no shielded assets, no further rewards should
Expand All @@ -640,7 +640,7 @@ fn masp_incentives() -> Result<()> {
)
});
assert!(captured.result.is_ok());
assert!(captured.contains("nam: 0.725855"));
assert!(captured.contains("nam: 1.451732"));

// Assert NAM balance at MASP pool is
// the accumulation of rewards from the shielded assets (BTC and ETH)
Expand All @@ -660,11 +660,11 @@ fn masp_incentives() -> Result<()> {
)
});
assert!(captured.result.is_ok());
assert!(captured.contains("nam: 1.843775"));
assert!(captured.contains("nam: 3.723616"));

// Wait till epoch boundary to prevent conversion expiry during transaction
// construction
node.next_epoch();
node.next_masp_epoch();
// sync the shielded context
run(
&node,
Expand All @@ -685,7 +685,7 @@ fn masp_incentives() -> Result<()> {
"--token",
NAM,
"--amount",
"0.725855",
"1.451732",
"--signing-keys",
BERTHA_KEY,
"--node",
Expand All @@ -695,7 +695,7 @@ fn masp_incentives() -> Result<()> {
node.assert_success();

// Wait till epoch boundary
node.next_epoch();
node.next_masp_epoch();
// sync the shielded context
run(
&node,
Expand All @@ -716,7 +716,7 @@ fn masp_incentives() -> Result<()> {
"--token",
NAM,
"--amount",
"1.113911",
"2.268662",
"--signing-keys",
ALBERT_KEY,
"--node",
Expand Down Expand Up @@ -795,7 +795,7 @@ fn masp_incentives() -> Result<()> {
)
});
assert!(captured.result.is_ok());
assert!(captured.contains("nam: 0.004009"));
assert!(captured.contains("nam: 0.003222"));

Ok(())
}
Expand Down Expand Up @@ -1683,7 +1683,7 @@ fn dynamic_assets() -> Result<()> {
)?;
node.assert_success();
// Wait till epoch boundary
node.next_epoch();
node.next_masp_epoch();
// Send 1 BTC from Albert to PA
run(
&node,
Expand Down Expand Up @@ -1770,7 +1770,7 @@ fn dynamic_assets() -> Result<()> {
}

// Wait till epoch boundary
node.next_epoch();
node.next_masp_epoch();
// sync the shielded context
run(
&node,
Expand Down Expand Up @@ -1884,7 +1884,7 @@ fn dynamic_assets() -> Result<()> {
assert!(captured.contains("nam: 0"));

// Wait till epoch boundary
node.next_epoch();
node.next_masp_epoch();
// sync the shielded context
run(
&node,
Expand All @@ -1910,7 +1910,7 @@ fn dynamic_assets() -> Result<()> {
)
});
assert!(captured.result.is_ok());
assert!(captured.contains("nam: 0.0303"));
assert!(captured.contains("nam: 0.06262"));

// Assert BTC balance at VK(A) is still 2
let captured = CapturedOutput::of(|| {
Expand Down Expand Up @@ -1945,7 +1945,7 @@ fn dynamic_assets() -> Result<()> {
}

// Wait till epoch boundary
node.next_epoch();
node.next_masp_epoch();
// sync the shielded context
run(
&node,
Expand Down Expand Up @@ -1990,7 +1990,7 @@ fn dynamic_assets() -> Result<()> {
)
});
assert!(captured.result.is_ok());
assert!(captured.contains("nam: 0.07575"));
assert!(captured.contains("nam: 0.15655"));

{
// Stop decoding and distributing shielded rewards for BTC in next epoch
Expand All @@ -2012,7 +2012,7 @@ fn dynamic_assets() -> Result<()> {
}

// Wait till epoch boundary
node.next_epoch();
node.next_masp_epoch();
// sync the shielded context
run(
&node,
Expand Down Expand Up @@ -2057,10 +2057,10 @@ fn dynamic_assets() -> Result<()> {
)
});
assert!(captured.result.is_ok());
assert!(captured.contains("nam: 0.07575"));
assert!(captured.contains("nam: 0.15655"));

// Wait till epoch boundary
node.next_epoch();
node.next_masp_epoch();
// sync the shielded context
run(
&node,
Expand Down Expand Up @@ -2104,7 +2104,7 @@ fn dynamic_assets() -> Result<()> {
)
});
assert!(captured.result.is_ok());
assert!(captured.contains("nam: 0.07575"));
assert!(captured.contains("nam: 0.15655"));

{
// Start distributing shielded rewards for NAM in next epoch
Expand All @@ -2120,7 +2120,7 @@ fn dynamic_assets() -> Result<()> {
}

// Wait till epoch boundary
node.next_epoch();
node.next_masp_epoch();
// sync the shielded context
run(
&node,
Expand Down Expand Up @@ -2164,7 +2164,7 @@ fn dynamic_assets() -> Result<()> {
)
});
assert!(captured.result.is_ok());
assert!(captured.contains("nam: 0.075825"));
assert!(captured.contains("nam: 0.156705"));

Ok(())
}

0 comments on commit 8cd7e79

Please sign in to comment.