-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creates tests for panic errors support (#510)
* Drafts tests for panic errors support Signed-off-by: Konstantina Blazhukova <[email protected]> * Fixes PR comments Signed-off-by: Konstantina Blazhukova <[email protected]> --------- Signed-off-by: Konstantina Blazhukova <[email protected]>
- Loading branch information
1 parent
2505c08
commit f19ed6d
Showing
3 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)]) | ||
}) | ||
}) |