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

test: authority rotation integration tests #3909

Merged
merged 25 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5aaa47a
Improved the current rotation test
syan095 Aug 17, 2023
053dd9c
Updated move_forward_blocks so it's more correct
syan095 Aug 17, 2023
6bf3526
Added 2 integration tests for when keygen and key handover fails
syan095 Aug 29, 2023
ecaf1a0
Merge remote-tracking branch 'origin/main' into test/authority-rotati…
syan095 Aug 29, 2023
26b04dd
Fixed integration tests
syan095 Aug 29, 2023
aa553df
Merge remote-tracking branch 'origin/main' into test/authority-rotati…
syan095 Aug 29, 2023
1d6d3d4
Fixed a bug where failed key handover cannot restart
syan095 Aug 29, 2023
dce1047
fix: use inherents and use correct execution order
dandanlen Aug 30, 2023
9c56078
fix: hacky fix for the authorities tests
dandanlen Aug 30, 2023
9733a90
WIP: Integration test's mock CFEs calls are put into a queue instead of
syan095 Sep 1, 2023
a872d75
Merge remote-tracking branch 'origin/main' into test/authority-rotati…
syan095 Sep 5, 2023
f88ff1c
Fixed broken build due to merge
syan095 Sep 5, 2023
9a619c5
Fixed authority rotation for integration test rig
syan095 Sep 7, 2023
4ed9c4d
Fixed all remaining integration tests
syan095 Sep 8, 2023
8cf6ccf
Minor typo changes
syan095 Sep 8, 2023
b84c3d7
Merge remote-tracking branch 'origin/main' into test/authority-rotati…
syan095 Sep 8, 2023
2a00639
fix: reset events
dandanlen Sep 11, 2023
3ee6830
minor refactor
syan095 Sep 11, 2023
9dee0c9
Included integrity test to the test harness
syan095 Sep 12, 2023
9e9bea9
Merged from main.
syan095 Sep 13, 2023
78c63a6
Merged from main
syan095 Sep 15, 2023
8f1efa7
chore: more explicit error message in vault handover
dandanlen Sep 18, 2023
0042cdd
fix: process contract events before block
dandanlen Sep 18, 2023
a2d138f
fix: import the runtime VaultRotator
dandanlen Sep 18, 2023
a7fdf43
Merge branch 'main' into test/authority-rotation-integration
dandanlen Sep 18, 2023
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions state-chain/amm/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,13 @@ pub(super) fn sqrt_price_at_tick(tick: Tick) -> SqrtPriceQ64F96 {
/* Proof that r is never zero (therefore avoiding the divide by zero case here):
We can think of an application of the `handle_tick_bit` macro as increasing the index I of r's MSB/`r.ilog2()` (mul by constant), and then decreasing it by 128 (the right shift).

Note the increase in I caused by the constant mul will be atleast constant.ilog2().
Note the increase in I caused by the constant mul will be at least constant.ilog2().

Also note each application of `handle_tick_bit` decreases (if the if branch is entered) or else maintains r's value as all the constants are less than 2^128.

Therefore the largest decrease would be caused if all the macros application's if branches where entered.

So we assuming all if branches are entered, after all the applications `I` would be atleast I_initial + bigsum(constant.ilog2()) - 19*128.
So we assuming all if branches are entered, after all the applications `I` would be at least I_initial + bigsum(constant.ilog2()) - 19*128.

The test `r_non_zero` checks with value is >= 0, therefore imply the smallest value r could have is more than 0.
*/
Expand Down
12 changes: 6 additions & 6 deletions state-chain/amm/src/limit_orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl FloatBetweenZeroAndOne {

let (mul_div_normalised_mantissa, div_normalise_shift) = {
// As the denominator <= U256::MAX, this div will not right-shift the mantissa more than
// 256 bits, so we maintain atleast 256 accurate bits in the result.
// 256 bits, so we maintain at least 256 accurate bits in the result.
let (d, div_remainder) =
U512::div_mod(mul_normalised_mantissa, U512::from(denominator));
let d = if div_remainder.is_zero() { d } else { d + U512::one() };
Expand All @@ -96,11 +96,11 @@ impl FloatBetweenZeroAndOne {
Self { normalised_mantissa: mul_div_normalised_mantissa, negative_exponent }
} else {
// This bounding will cause swaps to get bad prices, but this case will effectively
// never happen, as atleast (U256::MAX / 256) (~10^74) swaps would have to happen to get
// into this situation. TODO: A possible solution is disabling minting for pools "close"
// to this minimum. With a small change to the swapping logic it would be possible to
// guarantee that the pool would be emptied before percent_remaining could reach this
// min bound.
// never happen, as at least (U256::MAX / 256) (~10^74) swaps would have to happen to
// get into this situation. TODO: A possible solution is disabling minting for pools
// "close" to this minimum. With a small change to the swapping logic it would be
// possible to guarantee that the pool would be emptied before percent_remaining could
// reach this min bound.
Self { normalised_mantissa: U256::one() << 255, negative_exponent: U256::MAX }
}
}
Expand Down
2 changes: 2 additions & 0 deletions state-chain/cf-integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ targets = ['x86_64-unknown-linux-gnu']

[dependencies]
state-chain-runtime = { path = '../runtime' }
log = { version = '0.4.16', default-features = false }

[dev-dependencies]
libsecp256k1 = { version = "0.7", features = ['static-context'] }
Expand Down Expand Up @@ -78,3 +79,4 @@ sp-std = { git = "https://github.com/chainflip-io/substrate.git", tag = "chainfl
sp-transaction-pool = { git = "https://github.com/chainflip-io/substrate.git", tag = "chainflip-monthly-2023-08+1" }
sp-version = { git = "https://github.com/chainflip-io/substrate.git", tag = "chainflip-monthly-2023-08+1" }
sp-consensus-grandpa = { git = "https://github.com/chainflip-io/substrate.git", tag = "chainflip-monthly-2023-08+1" }
sp-timestamp = { git = "https://github.com/chainflip-io/substrate.git", tag = "chainflip-monthly-2023-08+1" }
13 changes: 12 additions & 1 deletion state-chain/cf-integration-tests/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ use crate::network;
use cf_chains::eth::Address as EthereumAddress;
use cf_primitives::GENESIS_EPOCH;
use cf_traits::EpochInfo;
use frame_support::traits::OnNewAccount;
use pallet_cf_funding::{MinimumFunding, RedemptionAmount};
use pallet_cf_reputation::Reputations;
use pallet_cf_validator::{AccountPeerMapping, MappedPeers, VanityNames};
use state_chain_runtime::{Reputation, Runtime, Validator};
use state_chain_runtime::{AccountRoles, Reputation, Runtime, Validator};

#[test]
fn account_deletion_removes_relevant_storage_items() {
Expand All @@ -28,6 +29,7 @@ fn account_deletion_removes_relevant_storage_items() {
);
testnet.move_forward_blocks(1);

AccountRoles::on_new_account(&backup_node);
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should not have to call this explicity - it should happen when the account is funded.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Update: I removed this and the extra funding call below.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Update 2: I reordered the processing of events - external (eth contract) events are now processed before the block, so we don't need 2 blocks to process the events.

network::Cli::register_as_validator(&backup_node);

network::setup_peer_mapping(&backup_node);
Expand All @@ -44,6 +46,15 @@ fn account_deletion_removes_relevant_storage_items() {
let vanity_names = VanityNames::<Runtime>::get();
assert_eq!(*vanity_names.get(&backup_node).unwrap(), elon_vanity_name.as_bytes().to_vec());

// Fund the account
testnet.state_chain_gateway_contract.fund_account(
backup_node.clone(),
crate::genesis::GENESIS_BALANCE,
GENESIS_EPOCH,
);
testnet.move_forward_blocks(2);

// Redeem all
network::Cli::redeem(
&backup_node,
RedemptionAmount::Max,
Expand Down
Loading