Skip to content

Commit

Permalink
Release 1.6.3. (#268)
Browse files Browse the repository at this point in the history
* Test counting the number of functions in our wasm contract (#265)
* Fix issue with admin only contract call (#267)
* Test for overriding state (#271)
  • Loading branch information
joshuajbouw authored Sep 16, 2021
1 parent f5bbd8b commit 3eace8c
Show file tree
Hide file tree
Showing 14 changed files with 151 additions and 33 deletions.
9 changes: 8 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.6.3] - 2021-09-14

### Changes

- Revert ERC20 admin address changes for the time being by [@joshuajbouw].

## [1.6.2] - 2021-09-13

### Changes
Expand Down Expand Up @@ -80,7 +86,8 @@ struct SubmitResult {

## [1.0.0] - 2021-05-12

[Unreleased]: https://github.com/aurora-is-near/aurora-engine/compare/1.6.2...master
[Unreleased]: https://github.com/aurora-is-near/aurora-engine/compare/1.6.3...master
[1.6.3]: https://github.com/aurora-is-near/aurora-engine/compare/1.6.2...1.6.3
[1.6.2]: https://github.com/aurora-is-near/aurora-engine/compare/1.6.1...1.6.2
[1.6.1]: https://github.com/aurora-is-near/aurora-engine/compare/1.6.0...1.6.1
[1.6.0]: https://github.com/aurora-is-near/aurora-engine/compare/1.5.0...1.6.0
Expand Down
4 changes: 3 additions & 1 deletion Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aurora-engine"
version = "1.6.2"
version = "1.6.3"
authors = ["NEAR <hello@near.org>"]
edition = "2018"
description = ""
Expand Down Expand Up @@ -76,6 +76,8 @@ near-crypto = { git = "https://github.com/near/nearcore.git", rev = "8a377fda0b4
near-vm-runner = { git = "https://github.com/near/nearcore.git", rev = "8a377fda0b4ce319385c463f1ae46e4b0b29dcd9"}
near-vm-logic = { git = "https://github.com/near/nearcore.git", rev = "8a377fda0b4ce319385c463f1ae46e4b0b29dcd9"}
near-primitives-core = { git = "https://github.com/near/nearcore.git", rev = "8a377fda0b4ce319385c463f1ae46e4b0b29dcd9"}
near-primitives = { git = "https://github.com/near/nearcore.git", rev = "8a377fda0b4ce319385c463f1ae46e4b0b29dcd9"}
wasmer-runtime-core = { version = "0.18.2", package = "wasmer-runtime-core-near"}
libsecp256k1 = "0.3.5"
rand = "0.7.3"
criterion = "0.3.4"
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ documentation.

Network | Contract ID | Chain ID | Version
------- | ------------------- | ---------- | ------
Mainnet | [`aurora`][Mainnet] | 1313161554 | 1.6.2
Testnet | [`aurora`][Testnet] | 1313161555 | 1.6.2
Betanet | [`aurora`][Betanet] | 1313161556 | 1.6.2
Local | `aurora.test.near` | 1313161556 | 1.6.2
Mainnet | [`aurora`][Mainnet] | 1313161554 | 1.6.3
Testnet | [`aurora`][Testnet] | 1313161555 | 1.6.3
Betanet | [`aurora`][Betanet] | 1313161556 | 1.6.3
Local | `aurora.test.near` | 1313161556 | 1.6.3

[Mainnet]: https://explorer.near.org/accounts/aurora
[Testnet]: https://explorer.testnet.near.org/accounts/aurora
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.6.2
1.6.3
2 changes: 1 addition & 1 deletion etc/state-migration-test/Cargo.lock

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

6 changes: 0 additions & 6 deletions src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crate::prelude::*;
use crate::storage::{self, EthConnectorStorageId, KeyPrefix};
use borsh::{BorshDeserialize, BorshSerialize};

pub(crate) const ERC20_ADMIN_PREFIX: &str = "erc20.";
pub(crate) const ERR_NOT_ENOUGH_BALANCE_FOR_FEE: &str = "ERR_NOT_ENOUGH_BALANCE_FOR_FEE";
pub const NO_DEPOSIT: Balance = 0;
const GAS_FOR_FINISH_DEPOSIT: Gas = 50_000_000_000_000;
Expand Down Expand Up @@ -633,11 +632,6 @@ impl EthConnectorContract {
}
}

pub(crate) fn erc20_admin_address(base_account_id: &[u8]) -> Address {
let erc20_admin_account_id = [ERC20_ADMIN_PREFIX.as_bytes(), base_account_id].concat();
crate::types::near_account_to_evm_address(erc20_admin_account_id.as_slice())
}

impl AdminControlled for EthConnectorContract {
fn get_paused(&self) -> PausedMask {
self.paused_mask
Expand Down
6 changes: 4 additions & 2 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use evm::executor::{MemoryStackState, StackExecutor, StackSubstateMetadata};
use evm::ExitFatal;
use evm::{Config, CreateScheme, ExitError, ExitReason};

use crate::connector::{self, EthConnectorContract};
use crate::connector::EthConnectorContract;
#[cfg(feature = "contract")]
use crate::contract::current_address;
use crate::map::{BijectionMap, LookupMap};
use crate::parameters::{
FunctionCallArgs, NEP141FtOnTransferArgs, NewCallArgs, PromiseCreateArgs, ResultLog,
Expand Down Expand Up @@ -789,7 +791,7 @@ impl Engine {
ethabi::Token::Uint(args.amount.into()),
]);

let erc20_admin_address = connector::erc20_admin_address(&sdk::current_account_id());
let erc20_admin_address = current_address();
unwrap_res_or_finish!(
self.call(
erc20_admin_address,
Expand Down
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub unsafe fn on_alloc_error(_: core::alloc::Layout) -> ! {
mod contract {
use borsh::{BorshDeserialize, BorshSerialize};

use crate::connector::{self, EthConnectorContract};
use crate::connector::EthConnectorContract;
use crate::engine::{Engine, EngineState, GasPaymentError};
use crate::fungible_token::FungibleTokenMetadata;
#[cfg(feature = "evm_bully")]
Expand Down Expand Up @@ -382,7 +382,7 @@ mod contract {

let mut engine = Engine::new(predecessor_address()).sdk_unwrap();

let erc20_admin_address = connector::erc20_admin_address(&sdk::current_account_id());
let erc20_admin_address = current_address();
let erc20_contract = include_bytes!("../etc/eth-contracts/res/EvmErc20.bin");
let deploy_args = ethabi::encode(&[
ethabi::Token::String("Empty".to_string()),
Expand Down Expand Up @@ -695,6 +695,10 @@ mod contract {
fn predecessor_address() -> Address {
near_account_to_evm_address(&sdk::predecessor_account_id())
}

pub fn current_address() -> Address {
near_account_to_evm_address(&sdk::current_account_id())
}
}

pub trait AuroraState {
Expand Down
4 changes: 0 additions & 4 deletions src/test_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ pub fn origin() -> AccountId {
"aurora".to_string()
}

pub fn erc20_admin_account() -> AccountId {
[crate::connector::ERC20_ADMIN_PREFIX, &origin()].concat()
}

pub(crate) const SUBMIT: &str = "submit";

pub(crate) mod erc20;
Expand Down
4 changes: 2 additions & 2 deletions src/tests/contract_call.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::test_utils::{AuroraRunner, Signer};
use crate::test_utils::{origin, AuroraRunner, Signer};

use crate::test_utils;
use crate::test_utils::exit_precompile::{Tester, TesterConstructor};
Expand All @@ -23,7 +23,7 @@ fn setup_test() -> (AuroraRunner, Signer, [u8; 20], Tester) {
token,
tester.contract.address.into(),
1_000_000_000,
test_utils::erc20_admin_account(),
origin(),
);

(runner, signer, token, tester)
Expand Down
9 changes: 2 additions & 7 deletions src/tests/erc20_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ fn test_mint() {
let balance = runner.balance_of(token, address, origin());
assert_eq!(balance, U256::from(0));
let amount = 10;
let _result = runner.mint(token, address, amount, test_utils::erc20_admin_account());
let _result = runner.mint(token, address, amount, origin());
let balance = runner.balance_of(token, address, origin());
assert_eq!(balance, U256::from(amount));
}
Expand Down Expand Up @@ -361,12 +361,7 @@ fn test_transfer_erc20_token() {
U256::zero()
);

runner.mint(
token,
peer0.address,
to_mint,
test_utils::erc20_admin_account(),
);
runner.mint(token, peer0.address, to_mint, origin());

assert_eq!(
runner.balance_of(token, peer0.address, origin()),
Expand Down
18 changes: 18 additions & 0 deletions src/tests/res/poster.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.8.6;

contract Poster {
event NewPost(address indexed user, string content);

address public sender_address;

function get() public view returns (address) {
return sender_address;
}

function post(string calldata content) public {
sender_address = msg.sender;
emit NewPost(sender_address, content);
}
}

100 changes: 99 additions & 1 deletion src/tests/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::prelude::{Address, U256};
use crate::test_utils;
use crate::tests::state_migration;
use crate::types::{self, Wei, ERC20_MINT_SELECTOR};
use borsh::BorshSerialize;
use borsh::{BorshDeserialize, BorshSerialize};
use secp256k1::SecretKey;
use std::path::{Path, PathBuf};

Expand All @@ -13,6 +13,87 @@ const INITIAL_NONCE: u64 = 0;
const TRANSFER_AMOUNT: Wei = Wei::new_u64(123);
const GAS_PRICE: u64 = 10;

#[test]
fn test_override_state() {
let (mut runner, mut account1, viewer_address) = initialize_transfer();
let account1_address = test_utils::address_from_secret_key(&account1.secret_key);
let mut account2 = test_utils::Signer::random();
let account2_address = test_utils::address_from_secret_key(&account2.secret_key);
runner.create_address(account2_address, INITIAL_BALANCE, INITIAL_NONCE.into());

let contract = test_utils::solidity::ContractConstructor::compile_from_source(
"src/tests/res",
"target/solidity_build",
"poster.sol",
"Poster",
);

// deploy contract
let result = runner
.submit_with_signer(&mut account1, |nonce| {
crate::transaction::LegacyEthTransaction {
nonce,
gas_price: Default::default(),
gas: u64::MAX.into(),
to: None,
value: Default::default(),
data: contract.code.clone(),
}
})
.unwrap();
let address = Address::from_slice(&test_utils::unwrap_success(result));
let contract = contract.deployed_at(address);

// define functions to interact with the contract
let get_address = |runner: &test_utils::AuroraRunner| {
let result = runner
.view_call(test_utils::as_view_call(
contract.call_method_without_args("get", U256::zero()),
viewer_address,
))
.unwrap();
match result {
crate::parameters::TransactionStatus::Succeed(bytes) => {
Address::from_slice(&bytes[12..32])
}
_ => panic!("tx failed"),
}
};

let post_address = |runner: &mut test_utils::AuroraRunner, signer: &mut test_utils::Signer| {
let result = runner
.submit_with_signer(signer, |nonce| {
contract.call_method_with_args(
"post",
&[ethabi::Token::String("Hello, world!".to_string())],
nonce,
)
})
.unwrap();
assert!(result.status.is_ok());
};

// Assert the initial state is 0
assert_eq!(get_address(&runner), Address([0; 20]));
post_address(&mut runner, &mut account1);
// Assert the address matches the first caller
assert_eq!(get_address(&runner), account1_address);
post_address(&mut runner, &mut account2);
// Assert the address matches the second caller
assert_eq!(get_address(&runner), account2_address);
}

#[test]
fn test_num_wasm_functions() {
// Counts the number of functions in our wasm output.
// See https://github.com/near/nearcore/issues/4814 for context
let runner = test_utils::deploy_evm();
let artifact = get_compiled_artifact(&runner);
let module_info = artifact.info();
let num_functions = module_info.func_assoc.len();
assert!(num_functions <= 1281);
}

/// Tests we can transfer Eth from one account to another and that the balances are correctly
/// updated.
#[test]
Expand Down Expand Up @@ -437,3 +518,20 @@ fn query_address_sim(
other => panic!("Unexpected outcome: {:?}", other),
}
}

fn get_compiled_artifact(
runner: &test_utils::AuroraRunner,
) -> wasmer_runtime_core::cache::Artifact {
use near_primitives::types::CompiledContractCache;

near_vm_runner::precompile_contract(&runner.code, &runner.wasm_config, Some(&runner.cache))
.unwrap();
let cache_key = near_vm_runner::get_contract_cache_key(
&runner.code,
Default::default(),
&runner.wasm_config,
);
let cache_record: Vec<u8> =
Vec::try_from_slice(&runner.cache.get(cache_key.as_ref()).unwrap().unwrap()[1..]).unwrap();
wasmer_runtime_core::cache::Artifact::deserialize(&cache_record).unwrap()
}

0 comments on commit 3eace8c

Please sign in to comment.