Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,13 @@ mod contract {
/// Must match CHAIN_ID to make sure it's signed for given chain vs replayed from another chain.
#[no_mangle]
pub extern "C" fn submit() {
use crate::transaction::EthSignedTransaction;
use rlp::{Decodable, Rlp};
use crate::prelude::TryFrom;
use crate::transaction::EthTransaction;

let input = sdk::read_input();
let signed_transaction =
EthSignedTransaction::decode(&Rlp::new(&input)).sdk_expect("ERR_INVALID_TX");

let EthTransaction::Legacy(signed_transaction) =
EthTransaction::try_from(input.as_slice()).sdk_unwrap();

let state = Engine::get_state().sdk_unwrap();

Expand Down
18 changes: 9 additions & 9 deletions src/test_utils/erc20.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::prelude::{Address, U256};
use crate::test_utils::solidity;
use crate::transaction::EthTransaction;
use crate::transaction::LegacyEthTransaction;
use std::path::{Path, PathBuf};
use std::sync::Once;

Expand All @@ -26,7 +26,7 @@ impl ERC20Constructor {
))
}

pub fn deploy(&self, name: &str, symbol: &str, nonce: U256) -> EthTransaction {
pub fn deploy(&self, name: &str, symbol: &str, nonce: U256) -> LegacyEthTransaction {
let data = self
.0
.abi
Expand All @@ -40,7 +40,7 @@ impl ERC20Constructor {
],
)
.unwrap();
EthTransaction {
LegacyEthTransaction {
nonce,
gas_price: Default::default(),
gas: u64::MAX.into(),
Expand Down Expand Up @@ -72,7 +72,7 @@ impl ERC20Constructor {
}

impl ERC20 {
pub fn mint(&self, recipient: Address, amount: U256, nonce: U256) -> EthTransaction {
pub fn mint(&self, recipient: Address, amount: U256, nonce: U256) -> LegacyEthTransaction {
let data = self
.0
.abi
Expand All @@ -84,7 +84,7 @@ impl ERC20 {
])
.unwrap();

EthTransaction {
LegacyEthTransaction {
nonce,
gas_price: Default::default(),
gas: u64::MAX.into(),
Expand All @@ -94,7 +94,7 @@ impl ERC20 {
}
}

pub fn transfer(&self, recipient: Address, amount: U256, nonce: U256) -> EthTransaction {
pub fn transfer(&self, recipient: Address, amount: U256, nonce: U256) -> LegacyEthTransaction {
let data = self
.0
.abi
Expand All @@ -105,7 +105,7 @@ impl ERC20 {
ethabi::Token::Uint(amount),
])
.unwrap();
EthTransaction {
LegacyEthTransaction {
nonce,
gas_price: Default::default(),
gas: u64::MAX.into(),
Expand All @@ -115,15 +115,15 @@ impl ERC20 {
}
}

pub fn balance_of(&self, address: Address, nonce: U256) -> EthTransaction {
pub fn balance_of(&self, address: Address, nonce: U256) -> LegacyEthTransaction {
let data = self
.0
.abi
.function("balanceOf")
.unwrap()
.encode_input(&[ethabi::Token::Address(address)])
.unwrap();
EthTransaction {
LegacyEthTransaction {
nonce,
gas_price: Default::default(),
gas: u64::MAX.into(),
Expand Down
8 changes: 4 additions & 4 deletions src/test_utils/exit_precompile.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::parameters::SubmitResult;
use crate::prelude::{Address, U256};
use crate::test_utils::{solidity, AuroraRunner, Signer};
use crate::transaction::EthTransaction;
use crate::transaction::LegacyEthTransaction;

pub(crate) struct TesterConstructor(pub solidity::ContractConstructor);

Expand All @@ -14,7 +14,7 @@ impl TesterConstructor {
))
}

pub fn deploy(&self, nonce: u64, token: Address) -> EthTransaction {
pub fn deploy(&self, nonce: u64, token: Address) -> LegacyEthTransaction {
let data = self
.0
.abi
Expand All @@ -23,7 +23,7 @@ impl TesterConstructor {
.encode_input(self.0.code.clone(), &[ethabi::Token::Address(token)])
.unwrap();

EthTransaction {
LegacyEthTransaction {
nonce: nonce.into(),
gas_price: Default::default(),
gas: U256::from(DEPLOY_CONTRACT_GAS),
Expand Down Expand Up @@ -67,7 +67,7 @@ impl Tester {
.encode_input(params)
.unwrap();

let tx = EthTransaction {
let tx = LegacyEthTransaction {
nonce: signer.use_nonce().into(),
gas_price: Default::default(),
gas: U256::from(DEPLOY_CONTRACT_GAS),
Expand Down
16 changes: 8 additions & 8 deletions src/test_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::fungible_token::FungibleToken;
use crate::parameters::{InitCallArgs, NewCallArgs, PromiseCreateArgs, SubmitResult};
use crate::prelude::Address;
use crate::test_utils::solidity::{ContractConstructor, DeployedContract};
use crate::transaction::{EthSignedTransaction, EthTransaction};
use crate::transaction::{LegacyEthSignedTransaction, LegacyEthTransaction};
use crate::types;
use crate::types::AccountId;
use crate::{storage, AuroraState};
Expand Down Expand Up @@ -218,7 +218,7 @@ impl AuroraRunner {
pub fn submit_transaction(
&mut self,
account: &SecretKey,
transaction: EthTransaction,
transaction: LegacyEthTransaction,
) -> Result<SubmitResult, VMError> {
let calling_account_id = "some-account.near".to_string();
let signed_tx = sign_transaction(transaction, Some(self.chain_id), account);
Expand All @@ -236,7 +236,7 @@ impl AuroraRunner {
}
}

pub fn deploy_contract<F: FnOnce(&T) -> EthTransaction, T: Into<ContractConstructor>>(
pub fn deploy_contract<F: FnOnce(&T) -> LegacyEthTransaction, T: Into<ContractConstructor>>(
&mut self,
account: &SecretKey,
constructor_tx: F,
Expand Down Expand Up @@ -369,9 +369,9 @@ pub(crate) fn create_eth_transaction(
data: Vec<u8>,
chain_id: Option<u64>,
secret_key: &SecretKey,
) -> EthSignedTransaction {
) -> LegacyEthSignedTransaction {
// nonce, gas_price and gas are not used by EVM contract currently
let tx = EthTransaction {
let tx = LegacyEthTransaction {
nonce: Default::default(),
gas_price: Default::default(),
gas: u64::MAX.into(),
Expand All @@ -383,10 +383,10 @@ pub(crate) fn create_eth_transaction(
}

pub(crate) fn sign_transaction(
tx: EthTransaction,
tx: LegacyEthTransaction,
chain_id: Option<u64>,
secret_key: &SecretKey,
) -> EthSignedTransaction {
) -> LegacyEthSignedTransaction {
let mut rlp_stream = RlpStream::new();
tx.rlp_append_unsigned(&mut rlp_stream, chain_id);
let message_hash = types::keccak(rlp_stream.as_raw());
Expand All @@ -399,7 +399,7 @@ pub(crate) fn sign_transaction(
};
let r = U256::from_big_endian(&signature.r.b32());
let s = U256::from_big_endian(&signature.s.b32());
EthSignedTransaction {
LegacyEthSignedTransaction {
transaction: tx,
v,
r,
Expand Down
14 changes: 7 additions & 7 deletions src/test_utils/self_destruct.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::parameters::FunctionCallArgs;
use crate::prelude::Address;
use crate::test_utils::{solidity, AuroraRunner, Signer};
use crate::transaction::EthTransaction;
use crate::transaction::LegacyEthTransaction;
use borsh::BorshSerialize;
use primitive_types::U256;
use std::convert::TryInto;
Expand All @@ -17,7 +17,7 @@ impl SelfDestructFactoryConstructor {
))
}

pub fn deploy(&self, nonce: u64) -> EthTransaction {
pub fn deploy(&self, nonce: u64) -> LegacyEthTransaction {
let data = self
.0
.abi
Expand All @@ -26,7 +26,7 @@ impl SelfDestructFactoryConstructor {
.encode_input(self.0.code.clone(), &[])
.unwrap();

EthTransaction {
LegacyEthTransaction {
nonce: nonce.into(),
gas_price: Default::default(),
gas: U256::from(DEFAULT_GAS),
Expand Down Expand Up @@ -63,7 +63,7 @@ impl SelfDestructFactory {
.encode_input(&[])
.unwrap();

let tx = EthTransaction {
let tx = LegacyEthTransaction {
nonce: signer.use_nonce().into(),
gas_price: Default::default(),
gas: U256::from(DEFAULT_GAS),
Expand Down Expand Up @@ -101,7 +101,7 @@ impl SelfDestruct {
.encode_input(&[])
.unwrap();

let tx = EthTransaction {
let tx = LegacyEthTransaction {
nonce: signer.use_nonce().into(),
gas_price: Default::default(),
gas: U256::from(DEFAULT_GAS),
Expand Down Expand Up @@ -130,7 +130,7 @@ impl SelfDestruct {
.encode_input(&[])
.unwrap();

let tx = EthTransaction {
let tx = LegacyEthTransaction {
nonce: signer.use_nonce().into(),
gas_price: Default::default(),
gas: U256::from(DEFAULT_GAS),
Expand All @@ -151,7 +151,7 @@ impl SelfDestruct {
.encode_input(&[])
.unwrap();

let tx = EthTransaction {
let tx = LegacyEthTransaction {
nonce: signer.use_nonce().into(),
gas_price: Default::default(),
gas: U256::from(DEFAULT_GAS),
Expand Down
10 changes: 5 additions & 5 deletions src/test_utils/standard_precompiles.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::prelude::U256;
use crate::test_utils::solidity;
use crate::transaction::EthTransaction;
use crate::transaction::LegacyEthTransaction;
use std::path::{Path, PathBuf};

pub(crate) struct PrecompilesConstructor(pub solidity::ContractConstructor);
Expand All @@ -23,15 +23,15 @@ impl PrecompilesConstructor {
))
}

pub fn deploy(&self, nonce: U256) -> EthTransaction {
pub fn deploy(&self, nonce: U256) -> LegacyEthTransaction {
let data = self
.0
.abi
.constructor()
.unwrap()
.encode_input(self.0.code.clone(), &[])
.unwrap();
EthTransaction {
LegacyEthTransaction {
nonce,
gas_price: Default::default(),
gas: u64::MAX.into(),
Expand All @@ -51,15 +51,15 @@ impl PrecompilesConstructor {
}

impl PrecompilesContract {
pub fn call_method(&self, method_name: &str, nonce: U256) -> EthTransaction {
pub fn call_method(&self, method_name: &str, nonce: U256) -> LegacyEthTransaction {
let data = self
.0
.abi
.function(method_name)
.unwrap()
.encode_input(&[])
.unwrap();
EthTransaction {
LegacyEthTransaction {
nonce,
gas_price: Default::default(),
gas: u64::MAX.into(),
Expand Down
8 changes: 6 additions & 2 deletions src/tests/erc20_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::parameters::{FunctionCallArgs, SubmitResult};
use crate::prelude::*;
use crate::test_utils;
use crate::test_utils::{create_eth_transaction, origin, AuroraRunner};
use crate::transaction::EthSignedTransaction;
use crate::transaction::LegacyEthSignedTransaction;
use crate::types::{AccountId, Balance, RawAddress, Wei};
use borsh::{BorshDeserialize, BorshSerialize};
use ethabi::Token;
Expand Down Expand Up @@ -105,7 +105,11 @@ impl test_utils::AuroraRunner {
)
}

pub fn evm_submit(&mut self, input: EthSignedTransaction, origin: AccountId) -> CallResult {
pub fn evm_submit(
&mut self,
input: LegacyEthSignedTransaction,
origin: AccountId,
) -> CallResult {
self.make_call("submit", origin, rlp::encode(&input).to_vec())
}

Expand Down
6 changes: 3 additions & 3 deletions src/tests/sanity.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::prelude::Address;
use crate::test_utils;
use crate::transaction::EthTransaction;
use crate::transaction::LegacyEthTransaction;
use crate::types::{Wei, ERC20_MINT_SELECTOR};
use secp256k1::SecretKey;

Expand Down Expand Up @@ -98,7 +98,7 @@ fn test_eth_transfer_insufficient_balance() {
fn test_eth_transfer_incorrect_nonce() {
let (mut runner, source_account, dest_address) = initialize_transfer();
let source_address = test_utils::address_from_secret_key(&source_account);
let transaction = EthTransaction {
let transaction = LegacyEthTransaction {
nonce: (INITIAL_NONCE + 1).into(),
gas_price: Default::default(),
gas: Default::default(),
Expand Down Expand Up @@ -139,7 +139,7 @@ fn test_eth_transfer_incorrect_nonce() {
fn test_eth_transfer_not_enough_gas() {
let (mut runner, source_account, dest_address) = initialize_transfer();
let source_address = test_utils::address_from_secret_key(&source_account);
let transaction = EthTransaction {
let transaction = LegacyEthTransaction {
nonce: INITIAL_NONCE.into(),
gas_price: Default::default(),
gas: 10_000.into(), // this is not enough gas
Expand Down
Loading