Skip to content

Commit

Permalink
fix tests and update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
imabdulbasit committed Aug 14, 2024
1 parent e6cf990 commit 8d7de78
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 18 deletions.
23 changes: 16 additions & 7 deletions doc/upgrades.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,34 @@ TOML file. For an example with upgrades enabled, refer to [`data/genesis/demo.to
```toml
[[upgrade]]
version = "0.2"
view = 5
propose_window = 10
start_proposing_view = 5
stop_proposing_view = 15

[upgrade.chain_config]
[upgrade.fee_upgrade]

[upgrade.fee_upgrade.chain_config]
chain_id = 999999999
base_fee = '2 wei'
base_fee = '1 wei'
max_block_size = '1mb'
fee_recipient = '0x0000000000000000000000000000000000000000'
fee_contract = '0xa15bb66138824a1c7167f5e85b957d04dd34e468'

[[upgrade]]
version = "0.3"
start_proposing_view = 5
stop_proposing_view = 15

[upgrade.marketplace]
```

In the TOML configuration example above, the `upgrade` section defines an array of tables, each specifying upgrade
parameters:

- **Version:** the new version after an upgrade is successful.
- **View:** Represents the `start_proposing_view` value at which the upgrade is proposed.
- **Propose Window:** Refers to the view window between `start_proposing_view` and `stop_proposing_view`.
- **start_proposing_view:** Represents the `start_proposing_view` value at which the upgrade is proposed.
- **stop_proposing_view:** Refers to the view at which the proposing an upgrade has stopped.

The `upgrade.chain_config` table contains the complete set of chain config parameters, which can be used, for example,
The `upgrade.fee_upgrade.chain_config` table contains the complete set of chain config parameters, which can be used, for example,
to enable protocol fees or modify other parameters.

## Fee upgrade
Expand Down
10 changes: 5 additions & 5 deletions sequencer/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1431,10 +1431,10 @@ mod test {
}

#[async_std::test]
async fn test_chain_config_upgrade_view_based() {
async fn test_fee_upgrade_view_based() {
setup_test();

test_chain_config_upgrade_helper(UpgradeMode::View(ViewBasedUpgrade {
test_fee_upgrade_helper(UpgradeMode::View(ViewBasedUpgrade {
start_voting_view: None,
stop_voting_view: None,
start_proposing_view: 1,
Expand All @@ -1444,11 +1444,11 @@ mod test {
}

#[async_std::test]
async fn test_chain_config_upgrade_time_based() {
async fn test_fee_upgrade_time_based() {
setup_test();

let now = OffsetDateTime::now_utc().unix_timestamp() as u64;
test_chain_config_upgrade_helper(UpgradeMode::Time(TimeBasedUpgrade {
test_fee_upgrade_helper(UpgradeMode::Time(TimeBasedUpgrade {
start_proposing_time: Timestamp::from_integer(now).unwrap(),
stop_proposing_time: Timestamp::from_integer(now + 500).unwrap(),
start_voting_time: None,
Expand All @@ -1457,7 +1457,7 @@ mod test {
.await;
}

async fn test_chain_config_upgrade_helper(mode: UpgradeMode) {
async fn test_fee_upgrade_helper(mode: UpgradeMode) {
let port = pick_unused_port().expect("No ports free");
let anvil = Anvil::new().spawn();
let l1 = anvil.endpoint().parse().unwrap();
Expand Down
68 changes: 62 additions & 6 deletions sequencer/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ mod test {
}

#[test]
fn test_genesis_toml_upgrade_view_mode() {
fn test_genesis_toml_fee_upgrade_view_mode() {
// without optional fields
// with view settings
let toml = toml! {
Expand Down Expand Up @@ -463,7 +463,7 @@ mod test {
}

#[test]
fn test_genesis_toml_upgrade_time_mode() {
fn test_genesis_toml_fee_upgrade_time_mode() {
// without optional fields
// with time settings
let toml = toml! {
Expand Down Expand Up @@ -494,7 +494,9 @@ mod test {
start_proposing_time = "2024-01-01T00:00:00Z"
stop_proposing_time = "2024-01-02T00:00:00Z"

[upgrade.chain_config]
[upgrade.fee_upgrade]

[upgrade.fee_upgrade.chain_config]
chain_id = 12345
max_block_size = 30000
base_fee = 1
Expand Down Expand Up @@ -527,7 +529,7 @@ mod test {
}

#[test]
fn test_genesis_toml_upgrade_view_and_time_mode() {
fn test_genesis_toml_fee_upgrade_view_and_time_mode() {
// set both time and view parameters
// this should err
let toml = toml! {
Expand Down Expand Up @@ -560,7 +562,9 @@ mod test {
start_proposing_time = 1
stop_proposing_time = 10

[upgrade.chain_config]
[upgrade.fee_upgrade]

[upgrade.fee_upgrade.chain_config]
chain_id = 12345
max_block_size = 30000
base_fee = 1
Expand Down Expand Up @@ -597,12 +601,64 @@ mod test {
timestamp = "0x123def"
hash = "0x80f5dd11f2bdda2814cb1ad94ef30a47de02cf28ad68c89e104c00c4e51bb7a5"


[[upgrade]]
version = "0.3"
start_proposing_view = 1
stop_proposing_view = 10

[upgrade.marketplace]
}
.to_string();

toml::from_str::<Genesis>(&toml).unwrap();
}

#[test]
fn test_marketplace_and_fee_upgrade_toml() {
let toml = toml! {
[stake_table]
capacity = 10

[chain_config]
chain_id = 12345
max_block_size = 30000
base_fee = 1
fee_recipient = "0x0000000000000000000000000000000000000000"
fee_contract = "0x0000000000000000000000000000000000000000"

[header]
timestamp = 123456

[accounts]
"0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f" = 100000
"0x0000000000000000000000000000000000000000" = 42

[l1_finalized]
number = 64
timestamp = "0x123def"
hash = "0x80f5dd11f2bdda2814cb1ad94ef30a47de02cf28ad68c89e104c00c4e51bb7a5"

[[upgrade]]
version = "0.4"
version = "0.3"
start_proposing_view = 1
stop_proposing_view = 10

[upgrade.marketplace]

[[upgrade]]
version = "0.2"
start_proposing_view = 1
stop_proposing_view = 15

[upgrade.fee_upgrade]

[upgrade.fee_upgrade.chain_config]
chain_id = 12345
max_block_size = 30000
base_fee = 1
fee_recipient = "0x0000000000000000000000000000000000000000"
fee_contract = "0x0000000000000000000000000000000000000000"
}
.to_string();

Expand Down

0 comments on commit 8d7de78

Please sign in to comment.