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

Adding tests for inheritance #474

Merged
merged 3 commits into from
Oct 18, 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
13 changes: 13 additions & 0 deletions contracts/solidity/inhetitance/Base.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

contract Base {
receive() external payable {}
function classIdentifier() public pure virtual returns (string memory) {
return "Base";
}

function getBalance() public view returns (uint256) {
return address(this).balance;
}
}
stefan-stefanooov marked this conversation as resolved.
Show resolved Hide resolved
21 changes: 21 additions & 0 deletions contracts/solidity/inhetitance/Main.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
import { Base } from "./Base.sol";

contract Main is Base {
function classIdentifier() public pure override(Base) returns (string memory) {
return "Main";
}

function returnThis() public view returns (Main) {
return this;
}

function returnSuper() public view virtual returns (string memory) {
return super.classIdentifier();
}

function destroyContract(address recipient) public {
selfdestruct(payable(recipient));
}
}
stefan-stefanooov marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions test/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ const Contract = {
New: 'New',
AddressContract: 'AddressContract',
Recipient: 'Recipient',
Inheritance: 'Inheritance',
}

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

describe('Crypto Inheritance tests', function () {
let signers, contractMain, contractBase, wallet
const TOP_UP_AMOUNT = ethers.utils.parseEther('0.000001');

before(async function () {
signers = await ethers.getSigners()
wallet = signers[0];

const factoryMain = await ethers.getContractFactory('Main')
contractMain = await factoryMain.deploy()
await contractMain.deployed()

const factoryBase = await ethers.getContractFactory('Base')
contractBase = await factoryBase.deploy()
await contractBase.deployed()

//top up the test contract with some funds
const tx = {
to: contractMain.address,
value: TOP_UP_AMOUNT
}
const topUpRes = await wallet.sendTransaction(tx)
await topUpRes.wait();
})

it('should confirm solidity functionality: this (current contract\'s type)', async function () {
const mainThis = await contractMain.returnThis()

expect(mainThis).to.equal(contractMain.address)
})

it('should confirm solidity functionality: super', async function () {
const res = await contractMain.classIdentifier()

expect(res).to.equal("Main")
})

it('should confirm solidity functionality: selfdestruct(address payable recipient)', async function () {
const balanceBaseInitial = await contractBase.getBalance()
expect(balanceBaseInitial).to.be.equal(0)

const tx = await contractMain.destroyContract(contractBase.address)
await tx.wait()
const balanceBaseFinal = await contractBase.getBalance()

expect(balanceBaseFinal.gt(balanceBaseInitial)).to.be.true
})

})