Skip to content

Commit

Permalink
contracts: check constructor error handling in eth_call
Browse files Browse the repository at this point in the history
  • Loading branch information
CedarMist committed Mar 27, 2024
1 parent d88a826 commit 89fe417
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 13 deletions.
14 changes: 14 additions & 0 deletions contracts/contracts/tests/CreateFailCustom.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8.0;

contract CreateFailCustom {
uint256 constant ERROR_NUM =
0x1023456789abcdef1023456789abcdef1023456789abcdef1023456789abcdef;

error CustomError(uint256 value);

constructor () {
revert CustomError(ERROR_NUM);
}
}
9 changes: 9 additions & 0 deletions contracts/contracts/tests/CreateFailRequire.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8.0;

contract CreateFailRequire {
constructor () {
require(false, "ThisIsAnError");
}
}
34 changes: 32 additions & 2 deletions contracts/test/semantics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const ERROR_NUM =

describe('EVM Semantics', () => {
let c: SemanticTests;
let chainId: number;
let chainId: bigint;

before(async () => {
const f = await ethers.getContractFactory('SemanticTests');
Expand All @@ -19,18 +19,48 @@ describe('EVM Semantics', () => {
chainId = (await ethers.provider.getNetwork()).chainId;
});

it('eth_call constructor with custom error', async () => {
const f = await ethers.getContractFactory('CreateFailCustom');
const tx = await f.getDeployTransaction();
const p = ethers.provider;
try {
const r = await p.call({
data: tx.data
});
} catch(x: any) {
expect(x.revert.args[0]).to.eq(ERROR_NUM);
expect(x.revert.name).to.eq('CustomError');
}
});

it('eth_call constructor with require errror', async () => {
const f = await ethers.getContractFactory('CreateFailRequire');
const tx = await f.getDeployTransaction();
const p = ethers.provider;
try {
const r = await p.call({
data: tx.data
});
} catch(x: any) {
expect(x.revert.args[0]).to.eq('ThisIsAnError');
expect(x.revert.name).to.eq('Error');
}
});

it('eth_call maximum return length vs gas limit', async () => {
const i = 1211104;
const respHex = await c.testViewLength(i);
const respBytes = getBytes(respHex);
expect(respBytes.length).eq(i);

let caught = false;
try {
await c.testViewLength(i + 1);
expect(false).eq(true);
} catch (e: any) {
caught = true;
expect(e.info.error.message).contains('out of gas');
}
expect(caught).eq(true);
});

it('Error string in view call', async () => {
Expand Down
18 changes: 9 additions & 9 deletions runtime/Cargo.lock

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

4 changes: 2 additions & 2 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ debug = false
keymanager = { git = "https://github.com/oasisprotocol/keymanager-paratime", tag = "v0.4.1-testnet" }

# SDK.
module-evm = { git = "https://github.com/oasisprotocol/oasis-sdk", tag = "runtime-sdk/v0.8.3", package = "oasis-runtime-sdk-evm" }
oasis-runtime-sdk = { git = "https://github.com/oasisprotocol/oasis-sdk", tag = "runtime-sdk/v0.8.3" }
module-evm = { git = "https://github.com/oasisprotocol/oasis-sdk", branch = "kostko/feature/evm-simulate-create", package = "oasis-runtime-sdk-evm" }
oasis-runtime-sdk = { git = "https://github.com/oasisprotocol/oasis-sdk", branch = "kostko/feature/evm-simulate-create" }

# Third party.
once_cell = "1.8.0"
Expand Down
1 change: 1 addition & 0 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ impl sdk::Runtime for Runtime {
max_multisig_signers: 8,
gas_costs: modules::core::GasCosts {
tx_byte: 1,
storage_byte: 1,
auth_signature: 1_000,
auth_multisig_signer: 1_000,
callformat_x25519_deoxysii: 10_000,
Expand Down

0 comments on commit 89fe417

Please sign in to comment.