Skip to content

Commit

Permalink
Release 3.6.4 (#940)
Browse files Browse the repository at this point in the history
### Additions

- Added a possibility to provide amount of gas for the `state_migration`
callback in the `upgrade`
  transaction by @aleksuss. #937

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
aleksuss and dependabot[bot] authored Jul 22, 2024
1 parent 932412d commit 28396c1
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 54 deletions.
12 changes: 11 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [3.6.4] 2024-07-22

### Additions

- Added a possibility to provide amount of gas for the `state_migration` callback in the `upgrade`
transaction by [@aleksuss]. ([#937])

[#937]: https://github.com/aurora-is-near/aurora-engine/pull/937

## [3.6.3] 2024-04-16

### Additions
Expand Down Expand Up @@ -651,7 +660,8 @@ struct SubmitResult {

## [1.0.0] - 2021-05-12

[Unreleased]: https://github.com/aurora-is-near/aurora-engine/compare/3.6.3...develop
[Unreleased]: https://github.com/aurora-is-near/aurora-engine/compare/3.6.4...develop
[3.6.4]: https://github.com/aurora-is-near/aurora-engine/compare/3.6.3...3.6.4
[3.6.3]: https://github.com/aurora-is-near/aurora-engine/compare/3.6.2...3.6.3
[3.6.2]: https://github.com/aurora-is-near/aurora-engine/compare/3.6.1...3.6.2
[3.6.1]: https://github.com/aurora-is-near/aurora-engine/compare/3.6.0...3.6.1
Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.6.3
3.6.4
45 changes: 16 additions & 29 deletions engine-tests-connector/src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,7 @@ async fn test_ft_transfer_call_eth() -> anyhow::Result<()> {
);

let transfer_amount: U128 = 50.into();
let fee: u128 = 30;
let mut msg = U256::from(fee).as_byte_slice().to_vec();
msg.append(
&mut validate_eth_address(RECIPIENT_ETH_ADDRESS)
.as_bytes()
.to_vec(),
);

let message = [CONTRACT_ACC, hex::encode(msg).as_str()].join(":");
let message = ft_transfer_msg(CONTRACT_ACC, 30, RECIPIENT_ETH_ADDRESS);
let memo: Option<String> = None;
let res = user_acc
.call(contract.engine_contract.id(), "ft_transfer_call")
Expand Down Expand Up @@ -288,7 +280,7 @@ async fn test_ft_transfer_call_without_fee() -> anyhow::Result<()> {
);

let transfer_amount: U128 = 50.into();
let message = RECIPIENT_ETH_ADDRESS;
let message = ft_transfer_msg("relayer.root", 0, RECIPIENT_ETH_ADDRESS);
let memo: Option<String> = None;
let res = user_acc
.call(contract.engine_contract.id(), "ft_transfer_call")
Expand All @@ -302,7 +294,7 @@ async fn test_ft_transfer_call_without_fee() -> anyhow::Result<()> {
.deposit(ONE_YOCTO)
.transact()
.await?;
assert!(res.is_success());
assert!(res.is_success(), "{res:#?}");

assert_eq!(
contract.get_eth_on_near_balance(user_acc.id()).await?.0,
Expand Down Expand Up @@ -592,14 +584,7 @@ async fn test_ft_transfer_call_without_relayer() -> anyhow::Result<()> {
);

let transfer_amount: U128 = 50.into();
let fee: u128 = 30;
let mut msg = U256::from(fee).as_byte_slice().to_vec();
let recipient_address = validate_eth_address(RECIPIENT_ETH_ADDRESS);
msg.append(&mut recipient_address.as_bytes().to_vec());

let relayer_id = "relayer.root";
let message = [relayer_id, hex::encode(msg).as_str()].join(":");

let message = ft_transfer_msg("relayer.root", 30, RECIPIENT_ETH_ADDRESS);
let memo: Option<String> = None;
let res = user_acc
.call(contract.engine_contract.id(), "ft_transfer_call")
Expand All @@ -624,7 +609,9 @@ async fn test_ft_transfer_call_without_relayer() -> anyhow::Result<()> {
transfer_amount.0
);
assert_eq!(
contract.get_eth_balance(&recipient_address).await?,
contract
.get_eth_balance(&validate_eth_address(RECIPIENT_ETH_ADDRESS))
.await?,
transfer_amount.0
);
assert_eq!(contract.total_supply().await?, DEPOSITED_AMOUNT);
Expand All @@ -637,15 +624,7 @@ async fn test_ft_transfer_call_fee_greater_than_amount() -> anyhow::Result<()> {
contract.call_deposit_eth_to_near().await?;

let transfer_amount: U128 = 10.into();
let fee: u128 = 12;
let mut msg = U256::from(fee).as_byte_slice().to_vec();
msg.append(
&mut validate_eth_address(RECIPIENT_ETH_ADDRESS)
.as_bytes()
.to_vec(),
);
let relayer_id = "relayer.root";
let message = [relayer_id, hex::encode(msg).as_str()].join(":");
let message = ft_transfer_msg("relayer.root", 12, RECIPIENT_ETH_ADDRESS);
let memo: Option<String> = None;
let user_acc = contract
.create_sub_account(DEPOSITED_RECIPIENT_NAME)
Expand Down Expand Up @@ -1337,3 +1316,11 @@ async fn test_ft_metadata() -> anyhow::Result<()> {
assert_eq!(metadata.symbol, m.symbol);
Ok(())
}

fn ft_transfer_msg(relayer_id: &str, fee: u128, recipient: &str) -> String {
let mut msg = U256::from(fee).as_byte_slice().to_vec();
let recipient_address = validate_eth_address(recipient);

msg.extend(recipient_address.as_bytes());
[relayer_id, hex::encode(msg).as_str()].join(":")
}
10 changes: 9 additions & 1 deletion engine-tests-connector/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub struct TestContract {
}

impl TestContract {
pub async fn deploy_aurora_contract() -> anyhow::Result<(Contract, Contract, Account)> {
async fn deploy_aurora_contract() -> anyhow::Result<(Contract, Contract, Account)> {
use near_workspaces::{
types::{KeyType, SecretKey},
AccessKey,
Expand Down Expand Up @@ -141,6 +141,14 @@ impl TestContract {
.await?;
assert!(res.is_success());

let result = eth_connector_contract
.call("pa_unpause_feature")
.args_json(json!({ "key": "ALL" }))
.max_gas()
.transact()
.await?;
assert!(result.is_success(), "{result:#?}");

let chain_id = [0u8; 32];
let res = engine_contract
.call("new")
Expand Down
9 changes: 9 additions & 0 deletions engine-tests/src/utils/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ async fn init_eth_connector(aurora: &EngineContract) -> anyhow::Result<()> {
.await?;
assert!(result.is_success());

// By default, the contract is paused. So we need to unpause it.
let result = contract
.call("pa_unpause_feature")
.args_json(json!({ "key": "ALL" }))
.max_gas()
.transact()
.await?;
assert!(result.is_success());

let result = aurora
.set_eth_connector_contract_account(contract_account.id(), WithdrawSerializeType::Borsh)
.transact()
Expand Down
9 changes: 9 additions & 0 deletions engine-types/src/parameters/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,15 @@ pub struct RelayerKeyArgs {

pub type FullAccessKeyArgs = RelayerKeyArgs;

/// Parameters for upgrading the contract.
#[derive(Debug, Clone, Eq, PartialEq, BorshSerialize, BorshDeserialize)]
pub struct UpgradeParams {
/// Code for upgrading.
pub code: Vec<u8>,
/// Amount of gas for the state migration.
pub state_migration_gas: Option<u64>,
}

mod chain_id_deserialize {
use crate::types::{u256_to_arr, RawU256};
use primitive_types::U256;
Expand Down
2 changes: 1 addition & 1 deletion engine/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aurora-engine"
version = "3.6.3"
version = "3.6.4"
authors.workspace = true
edition.workspace = true
homepage.workspace = true
Expand Down
43 changes: 25 additions & 18 deletions engine/src/contract_methods/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use aurora_engine_sdk::{
io::{StorageIntermediate, IO},
promise::PromiseHandler,
};
use aurora_engine_types::parameters::engine::FullAccessKeyArgs;
use aurora_engine_types::parameters::engine::{FullAccessKeyArgs, UpgradeParams};
use aurora_engine_types::types::{NearGas, ZERO_YOCTO};
use aurora_engine_types::{
borsh::BorshDeserialize,
Expand All @@ -38,7 +38,7 @@ use aurora_engine_types::{
NewCallArgs, PausePrecompilesCallArgs, RelayerKeyArgs, RelayerKeyManagerArgs,
SetOwnerArgs, SetUpgradeDelayBlocksArgs, StartHashchainArgs,
},
promise::{PromiseAction, PromiseBatchAction, PromiseCreateArgs},
promise::{PromiseAction, PromiseBatchAction},
},
storage::{self, KeyPrefix},
types::{Address, Yocto},
Expand All @@ -48,7 +48,7 @@ use function_name::named;

const CODE_KEY: &[u8; 4] = b"CODE";
const CODE_STAGE_KEY: &[u8; 10] = b"CODE_STAGE";
const GAS_FOR_STATE_MIGRATION: NearGas = NearGas::new(100_000_000_000_000);
const GAS_FOR_STATE_MIGRATION: NearGas = NearGas::new(50_000_000_000_000);

#[named]
pub fn new<I: IO + Copy, E: Env>(mut io: I, env: &E) -> Result<(), ContractError> {
Expand Down Expand Up @@ -189,23 +189,30 @@ pub fn upgrade<I: IO + Copy, E: Env, H: PromiseHandler>(
require_running(&state)?;
require_owner_only(&state, &env.predecessor_account_id())?;

let code = io.read_input().to_vec();
let current_account_id = env.current_account_id();
let batch = PromiseBatchAction {
target_account_id: current_account_id.clone(),
actions: vec![PromiseAction::DeployContract { code }],
};
let state_migration_callback = PromiseCreateArgs {
target_account_id: current_account_id,
method: "state_migration".to_string(),
args: vec![],
attached_balance: ZERO_YOCTO,
attached_gas: GAS_FOR_STATE_MIGRATION,
let input = io.read_input().to_vec();
let (code, state_migration_gas) = match UpgradeParams::try_from_slice(&input) {
Ok(args) => (
args.code,
args.state_migration_gas
.map_or(GAS_FOR_STATE_MIGRATION, NearGas::new),
),
Err(_) => (input, GAS_FOR_STATE_MIGRATION), // Backward compatibility
};
let promise_id = unsafe {
let base_id = handler.promise_create_batch(&batch);
handler.promise_attach_callback(base_id, &state_migration_callback)

let target_account_id = env.current_account_id();
let batch = PromiseBatchAction {
target_account_id,
actions: vec![
PromiseAction::DeployContract { code },
PromiseAction::FunctionCall {
name: "state_migration".to_string(),
args: vec![],
attached_yocto: ZERO_YOCTO,
gas: state_migration_gas,
},
],
};
let promise_id = unsafe { handler.promise_create_batch(&batch) };

handler.promise_return(promise_id);

Expand Down

0 comments on commit 28396c1

Please sign in to comment.