Skip to content

Commit

Permalink
Drafts tests for panic errors support
Browse files Browse the repository at this point in the history
Signed-off-by: Konstantina Blazhukova <[email protected]>
  • Loading branch information
konstantinabl committed Nov 7, 2023
1 parent 2505c08 commit 326b5c3
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 0 deletions.
62 changes: 62 additions & 0 deletions contracts/solidity/errors/Panic.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

contract Panic {
uint[] someArray;
uint[] anotherArray = [1, 2, 3];

enum Button {
ON,
OFF
}
constructor() {
}

function testPanicError0x01() external pure {
assert(false);
}

function testPanicError0x11() external pure returns(uint8) {
uint8 test = 255;
uint8 test2 = 1;
return test + test2;
}

function testPanicError0x12() external pure returns(uint8) {
uint8 number1 = 5;
uint8 number2 = 12-12;
return number1 / number2;
}

function testPanicError0x21() external pure {
int testValue = -1;
Button value = Button(testValue);
}

function testPanicError0x22() external pure returns(uint8) {
return 0;
}

function testPanicError0x31() external {
someArray.pop();
}

function testPanicError0x32() external view returns(uint) {
return anotherArray[5];
}

function testPanicError0x41() external pure returns(uint[] memory) {
uint[] memory largeArray = new uint[](2**64);
}

function testPanicError0x51() external pure returns(uint) {
function (uint, uint) internal pure returns (uint) funcPtr;

return funcPtr(5, 6);
}

function getSomeArray() external view returns(uint[] memory) {
return someArray;
}

}
1 change: 1 addition & 0 deletions test/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ const Contract = {
Defaults: 'Defaults',
AssignmentReferenceTypes: 'AssignmentReferenceTypes',
DestructuringReturns: 'DestructuringReturns',
Panic: 'Panic'
}

const CALL_EXCEPTION = 'CALL_EXCEPTION'
Expand Down
103 changes: 103 additions & 0 deletions test/solidity/errors/panicErrors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
const { expect, assert } = require('chai')
const { ethers } = require('hardhat')
const Constants = require('../../constants')

describe('Panic Errors', function () {
let contract

before(async function () {
const factory = await ethers.getContractFactory(Constants.Contract.Panic)
contract = await factory.deploy()
})

it('should verify panic error 0x01', async function () {
let error;
try {
await contract.testPanicError0x01();
} catch(e) {
error = e;
}
expect(error.errorName).to.eq('Panic');
expect(error.errorArgs).to.deep.eq([ethers.BigNumber.from(1)])
})

it('should verify panic error 0x11', async function () {
let error;
try {
await contract.testPanicError0x11();
} catch(e) {
error = e;
}
expect(error.errorName).to.eq('Panic');
expect(error.errorArgs).to.deep.eq([ethers.BigNumber.from(17)])
})

it('should verify panic error 0x12', async function () {
let error;
try {
await contract.testPanicError0x12();
} catch(e) {
error = e;
}
expect(error.errorName).to.eq('Panic');
expect(error.errorArgs).to.deep.eq([ethers.BigNumber.from(18)])
})

it('should verify panic error 0x21', async function () {
let error;
try {
await contract.testPanicError0x21();
} catch(e) {
error = e;
}
expect(error.errorName).to.eq('Panic');
expect(error.errorArgs).to.deep.eq([ethers.BigNumber.from(33)])
})

it('should verify panic error 0x31', async function () {
let error;
try {
const result = await contract.getSomeArray();
console.log(result);
await contract.testPanicError0x31();
} catch(e) {
error = e;
}
expect(error.errorName).to.eq('Panic');
expect(error.errorArgs).to.deep.eq([ethers.BigNumber.from(18)])
})

it('should verify panic error 0x32', async function () {
let error;
try {
await contract.testPanicError0x32();
} catch(e) {
error = e;
}
expect(error.errorName).to.eq('Panic');
expect(error.errorArgs).to.deep.eq([ethers.BigNumber.from(50)])
})

it('should verify panic error 0x41', async function () {
let error;
try {
await contract.testPanicError0x41();
} catch(e) {
console.log(e)
error = e;
}
expect(error.errorName).to.eq('Panic');
expect(error.errorArgs).to.deep.eq([ethers.BigNumber.from(65)])
})

it('should verify panic error 0x51', async function () {
let error;
try {
await contract.testPanicError0x51();
} catch(e) {
error = e;
}
expect(error.errorName).to.eq('Panic');
expect(error.errorArgs).to.deep.eq([ethers.BigNumber.from(81)])
})
})

0 comments on commit 326b5c3

Please sign in to comment.