Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creates tests for panic errors support #510

Merged
merged 2 commits into from
Nov 7, 2023
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
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: Apache-2.0
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
123 changes: 123 additions & 0 deletions test/solidity/errors/panicErrors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*-
*
* Hedera Smart Contracts
*
* Copyright (C) 2023 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

const { expect } = require('chai')
const { ethers } = require('hardhat')
const Constants = require('../../constants')

describe('@solidityequiv3 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)])
})
})
Loading