Skip to content

Commit

Permalink
feat: add support get and set_upgrade_delay_blocks (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksuss authored Oct 11, 2023
1 parent de69403 commit 7a8551b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
Binary file modified docs/res/aurora-mainnet-silo.wasm
Binary file not shown.
14 changes: 11 additions & 3 deletions scripts/simple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

export NEARCORE_HOME="/tmp/localnet"

AURORA_PREV_VERSION="2.9.3"
AURORA_LAST_VERSION="2.10.0"
AURORA_PREV_VERSION="2.10.2"
AURORA_LAST_VERSION="3.1.0"
EVM_CODE=$(cat docs/res/HelloWorld.hex)
ABI_PATH="docs/res/HelloWorld.abi"
ENGINE_PREV_WASM_URL="https://github.com/aurora-is-near/aurora-engine/releases/download/$AURORA_PREV_VERSION/aurora-mainnet.wasm"
Expand Down Expand Up @@ -67,7 +67,7 @@ assert_eq() {
start_node
sleep 1

# Download Aurora EVM 2.8.1.
# Download Aurora EVM.
curl -sL $ENGINE_PREV_WASM_URL -o $ENGINE_WASM_PATH || error_exit

export NEAR_KEY_PATH=$NODE_KEY_PATH
Expand Down Expand Up @@ -217,5 +217,13 @@ aurora-cli --engine $ENGINE_ACCOUNT factory-set-wnear-address 0x80c6a002756e29b8
sleep 1
aurora-cli --engine $ENGINE_ACCOUNT fund-xcc-sub-account 0x43a4969cc2c22d0000c591ff4bd71983ea8a8be9 some_account.near 25.5 || error_exit

# Change upgrade delay blocks.
blocks=$(aurora-cli --engine $ENGINE_ACCOUNT get-upgrade-delay-blocks || error_exit)
assert_eq "$blocks" 1 # 1 is set on init stage
aurora-cli --engine $ENGINE_ACCOUNT set-upgrade-delay-blocks 5 || error_exit
sleep 1
blocks=$(aurora-cli --engine $ENGINE_ACCOUNT get-upgrade-delay-blocks || error_exit)
assert_eq "$blocks" 5

# Stop NEAR node and clean up.
finish
24 changes: 23 additions & 1 deletion src/cli/simple/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use aurora_engine_types::borsh::{self, BorshDeserialize, BorshSerialize};
use aurora_engine_types::parameters::connector::InitCallArgs;
use aurora_engine_types::parameters::engine::{
GetStorageAtArgs, NewCallArgs, NewCallArgsV2, PausePrecompilesCallArgs, RelayerKeyArgs,
RelayerKeyManagerArgs, SetOwnerArgs, SubmitResult, TransactionStatus,
RelayerKeyManagerArgs, SetOwnerArgs, SetUpgradeDelayBlocksArgs, SubmitResult,
TransactionStatus,
};
use aurora_engine_types::public_key::{KeyType, PublicKey};
use aurora_engine_types::types::Address;
Expand Down Expand Up @@ -63,6 +64,11 @@ pub async fn get_upgrade_index(client: Client) -> anyhow::Result<()> {
get_value::<u64>(client, "get_upgrade_index", None).await
}

/// Return a delay in block for an upgrade.
pub async fn get_upgrade_delay_blocks(client: Client) -> anyhow::Result<()> {
get_value::<u64>(client, "get_upgrade_delay_blocks", None).await
}

/// Return ETH balance of the address.
pub async fn get_balance(client: Client, address: String) -> anyhow::Result<()> {
let address = hex_to_vec(&address)?;
Expand Down Expand Up @@ -556,6 +562,22 @@ pub async fn remove_relayer_key(client: Client, public_key: PublicKey) -> anyhow
.await
}

/// Set a delay in blocks for an upgrade.
pub async fn set_upgrade_delay_blocks(client: Client, blocks: u64) -> anyhow::Result<()> {
let args = SetUpgradeDelayBlocksArgs {
upgrade_delay_blocks: blocks,
}
.try_to_vec()?;

contract_call!(
"set_upgrade_delay_blocks",
"Upgrade delay blocks: {blocks} has been set successfully",
"Error while setting upgrade delay blocks"
)
.proceed(client, args)
.await
}

async fn get_value<T: FromCallResult + Display>(
client: Client,
method_name: &str,
Expand Down
13 changes: 13 additions & 0 deletions src/cli/simple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,13 @@ pub enum Command {
/// Public key
public_key: PublicKey,
},
/// Get delay for upgrade in blocks
GetUpgradeDelayBlocks,
/// Set delay for upgrade in blocks
SetUpgradeDelayBlocks {
/// Number blocks
blocks: u64,
},
}

#[derive(Clone)]
Expand Down Expand Up @@ -435,6 +442,12 @@ pub async fn run(args: Cli) -> anyhow::Result<()> {
Command::RemoveRelayerKey { public_key } => {
command::remove_relayer_key(client, public_key).await?;
}
Command::GetUpgradeDelayBlocks => {
command::get_upgrade_delay_blocks(client).await?;
}
Command::SetUpgradeDelayBlocks { blocks } => {
command::set_upgrade_delay_blocks(client, blocks).await?;
}
}

Ok(())
Expand Down

0 comments on commit 7a8551b

Please sign in to comment.