Skip to content

Commit

Permalink
Addressing comments
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Stefanov <[email protected]>
  • Loading branch information
stefan-stefanooov committed Oct 18, 2023
1 parent 910ac91 commit 189393e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
23 changes: 6 additions & 17 deletions contracts/solidity/cryptomath/Arithmetic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,40 @@ contract Arithmetic {
return name;
}

function add() external returns (bool) {
function add() external {
name = "Arithmetic check if NOT reverted";
maxUint = maxUint + 1;
return true;
}

function add2() external returns (uint) {
function add2() external {
uint256 tmp = maxUint;
name = "Arithmetic check if NOT reverted";
tmp += 100;

return tmp;
}

function mul() external returns (bool) {
function mul() external {
uint8 maxUint8 = type(uint8).max;
name = "Arithmetic check if NOT reverted";
maxUint8 * 2;

return true;
}

function dec() external returns (bool) {
function dec() external {
// This subtraction will revert on underflow.
name = "Arithmetic check if NOT reverted";
minUint--;

return true;
}

function sub() external returns (bool) {
function sub() external {
uint256 tmp = minUint;
name = "Arithmetic check if NOT reverted";
tmp -= 1;

return true;
}

function negativeHasMoreValues() external returns (bool) {
function negativeHasMoreValues() external {
int tmp;
int x = type(int).min;
name = "Arithmetic check if NOT reverted";
tmp = -x;

return true;
}

function uncheckedAdd() external view returns (bool) {
Expand Down
22 changes: 19 additions & 3 deletions test/solidity/cryptomath/arithmetic.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,79 +22,95 @@ const { ethers } = require('hardhat')
const Constants = require('../../constants')

describe('Arithmetic Test Suite', function () {
let contract, signers;
let contract;

before(async function () {
signers = await ethers.getSigners()

const factory = await ethers.getContractFactory(Constants.Contract.Arithmetic)
contract = await factory.deploy()
});

it('it should confirm solidity functionality: Arithmetic, checked overflow - confirm revert add', async function () {
let hasError = false;
try {
const res = await contract.add()
await res.wait()
} catch (error) {
hasError = true;
expect(error).to.exist
const name = await contract.checkName()
expect(name).to.equal('Arithmetic')
}
expect(hasError).to.be.true;
});

it('it should confirm solidity functionality: Arithmetic, checked overflow - confirm revert add2', async function () {
let hasError = false;
try {
const res = await contract.add2()
await res.wait()
} catch (error) {
hasError = true;
expect(error).to.exist
const name = await contract.checkName()
expect(name).to.equal('Arithmetic')
}
expect(hasError).to.be.true;
});

it('it should confirm solidity functionality: Arithmetic, checked overflow - confirm revert mul', async function () {
let hasError = false;
try {
const res = await contract.mul()
await res.wait()
} catch (error) {
hasError = true;
expect(error).to.exist
const name = await contract.checkName()
expect(name).to.equal('Arithmetic')
}
expect(hasError).to.be.true;
});

it('it should confirm solidity functionality: Arithmetic, checked underflow - confirm revert sub', async function () {
let hasError = false;
try {
const res = await contract.sub()
await res.wait()
} catch (error) {
hasError = true;
expect(error).to.exist
const name = await contract.checkName()
expect(name).to.equal('Arithmetic')
}
expect(hasError).to.be.true;
});

it('it should confirm solidity functionality: Arithmetic, checked underflow - confirm revert dec', async function () {
let hasError = false;
try {
const res = await contract.dec()
await res.wait()
} catch (error) {
hasError = true;
expect(error).to.exist
const name = await contract.checkName()
expect(name).to.equal('Arithmetic')
}
expect(hasError).to.be.true;
});

it('it should confirm solidity functionality: Arithmetic, checked underflow - confirm revert negativeHasMoreValues', async function () {
let hasError = false;
try {
const res = await contract.negativeHasMoreValues()
await res.wait()
} catch (error) {
hasError = true;
expect(error).to.exist
const name = await contract.checkName()
expect(name).to.equal('Arithmetic')
}
expect(hasError).to.be.true;
});

it('it should confirm solidity functionality: Arithmetic, unchecked overflow - confirm wrap uncheckedAdd', async function () {
Expand Down

0 comments on commit 189393e

Please sign in to comment.