Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
fix: fix most of the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiendan committed Dec 8, 2023
1 parent 8b2dff5 commit 45d0fe0
Show file tree
Hide file tree
Showing 10 changed files with 1,943 additions and 3,552 deletions.
5,023 changes: 1,702 additions & 3,321 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"test": "hardhat test"
},
"devDependencies": {
"@nomicfoundation/hardhat-network-helpers": "^1.0.8",
"@nomicfoundation/hardhat-network-helpers": "^1.0.10",
"@nomicfoundation/hardhat-toolbox": "^4.0.0",
"@ethereumjs/rlp": "^4.0.1",
"@ethereumjs/trie": "^5.0.4",
Expand All @@ -49,7 +49,7 @@
"chai": "^4.3.7",
"eslint": "^8.38.0",
"eslint-config-prettier": "^8.8.0",
"hardhat": "2.14.0",
"hardhat": "^2.19.2",
"mocha": "^10.2.0",
"prettier": "^2.8.4",
"prettier-plugin-solidity": "^1.1.3",
Expand Down
5 changes: 3 additions & 2 deletions scripts/const-addr-deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
AbiCoder,
Contract,
ContractFactory,
HDNodeWallet,
InterfaceAbi,
keccak256,
Wallet,
Expand All @@ -21,7 +22,7 @@ const getSaltFromKey = (key: string) => {
}

export const estimateGasForDeploy = async (
wallet: Wallet,
wallet: Wallet | HDNodeWallet,
contractJson: ContractOutputJSON,
args: Arg[] = []
) => {
Expand Down Expand Up @@ -59,7 +60,7 @@ export const estimateGasForDeployAndInit = async (
}

export const deployContractConstant = async (
wallet: Wallet,
wallet: Wallet | HDNodeWallet,
contractJson: ContractOutputJSON,
key: string,
args: Arg[] = [],
Expand Down
53 changes: 28 additions & 25 deletions test/topos-core/BurnableMintableCappedERC20.test.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,44 @@
import { ethers } from 'hardhat'
import { EventLog } from 'ethers'
import { expect } from 'chai'
import { ethers } from 'hardhat'

import { BurnableMintableCappedERC20__factory } from '../../typechain-types/factories/contracts/topos-core/BurnableMintableCappedERC20__factory'
import { TokenDeployer__factory } from '../../typechain-types/factories/contracts/topos-core/TokenDeployer__factory'
import * as tc from './shared/constants/tokens'

describe('BurnableMintableCappedERC20', () => {
async function deployTokenFixture() {
const [deployer, operator, user1] = await ethers.getSigners()
const tokenSalt = ethers.utils.keccak256(
Buffer.from(deployer.address),
Buffer.from(tc.TOKEN_SYMBOL_X)
const tokenSalt = ethers.keccak256(
Buffer.concat([
Buffer.from(deployer.address),
Buffer.from(tc.TOKEN_SYMBOL_X),
])
)

const tokenDeployerFactory = await ethers.getContractFactory(
'TokenDeployer'
)
const BurnableMintableCappedERC20Factory = await ethers.getContractFactory(
'BurnableMintableCappedERC20'
)
const tokenDeployer = await new TokenDeployer__factory(deployer).deploy()
await tokenDeployer.waitForDeployment()

const tokenDeployer = await tokenDeployerFactory.deploy()
await tokenDeployer.deployed()

const tx = await tokenDeployer.deployToken(
const deployTokenTx = await tokenDeployer.deployToken(
tc.TOKEN_NAME,
tc.TOKEN_SYMBOL_X,
tc.MINT_CAP_100_000_000,
tc.INITIAL_SUPPLY_10_000_000,
deployer.address,
operator.address,
tokenSalt
tokenSalt,
{}
)

const txReceipt = await deployTokenTx.wait()
const log = txReceipt!.logs?.find(
(l) => (l as EventLog).eventName === 'Deployed'
)
const txReceipt = await tx.wait()
const logs = txReceipt.events?.find(
(e: { event: string }) => e.event === 'Deployed'
const tokenAddress = (log as EventLog).args['tokenAddress']
const token = BurnableMintableCappedERC20__factory.connect(
tokenAddress,
deployer
)
const tokenAddress = logs?.args?.tokenAddress
const token = BurnableMintableCappedERC20Factory.attach(tokenAddress)

return { deployer, operator, user1, token }
}
Expand Down Expand Up @@ -105,7 +108,7 @@ describe('BurnableMintableCappedERC20', () => {
const { deployer, operator, user1, token } = await deployTokenFixture()
await token
.connect(deployer)
.revokeRole(ethers.utils.id('OPERATOR_ROLE'), operator.address)
.revokeRole(ethers.id('OPERATOR_ROLE'), operator.address)
await expect(
token.connect(operator).mint(user1.address, tc.MINT_AMOUNT_100)
).to.be.revertedWith(
Expand All @@ -117,10 +120,10 @@ describe('BurnableMintableCappedERC20', () => {
const { deployer, operator, user1, token } = await deployTokenFixture()
await token
.connect(deployer)
.revokeRole(ethers.utils.id('OPERATOR_ROLE'), operator.address)
.revokeRole(ethers.id('OPERATOR_ROLE'), operator.address)
await token
.connect(deployer)
.grantRole(ethers.utils.id('OPERATOR_ROLE'), operator.address)
.grantRole(ethers.id('OPERATOR_ROLE'), operator.address)
await token.connect(operator).mint(user1.address, tc.MINT_AMOUNT_100)
await expect(token.balanceOf(user1.address)).to.eventually.equal(
tc.MINT_AMOUNT_100
Expand All @@ -132,7 +135,7 @@ describe('BurnableMintableCappedERC20', () => {
await expect(
token
.connect(operator)
.grantRole(ethers.utils.id('OPERATOR_ROLE'), user1.address)
.grantRole(ethers.id('OPERATOR_ROLE'), user1.address)
).to.be.reverted
})

Expand All @@ -141,7 +144,7 @@ describe('BurnableMintableCappedERC20', () => {
await expect(
token
.connect(operator)
.revokeRole(ethers.utils.id('OPERATOR_ROLE'), user1.address)
.revokeRole(ethers.id('OPERATOR_ROLE'), user1.address)
).to.be.reverted
})
})
Expand Down
6 changes: 3 additions & 3 deletions test/topos-core/Bytes32Sets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { expect } from 'chai'
describe('Bytes32Sets', () => {
let bytes32SetsTest: Contract

const key1 = ethers.utils.formatBytes32String('key1')
const key2 = ethers.utils.formatBytes32String('key2')
const key1 = ethers.encodeBytes32String('key1')
const key2 = ethers.encodeBytes32String('key2')

beforeEach(async () => {
const Bytes32SetsTest = await ethers.getContractFactory('Bytes32SetsTest')
bytes32SetsTest = await Bytes32SetsTest.deploy()
await bytes32SetsTest.deployed()
await bytes32SetsTest.waitForDeployment()
})

describe('insert', () => {
Expand Down
29 changes: 15 additions & 14 deletions test/topos-core/SubnetRegistrator.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { Contract, Wallet } from 'ethers'
import { Signer, Wallet } from 'ethers'
import { ethers } from 'hardhat'
import { expect } from 'chai'

describe('SubnetRegistrator', () => {
let subnetRegistrator: Contract
import { SubnetRegistrator__factory } from '../../typechain-types/factories/contracts/topos-core/SubnetRegistrator__factory'
import { SubnetRegistrator } from '../../typechain-types'

describe('SubnetRegistrator', () => {
const chainId = 1
const currencySymbol = 'SUB'
const endpointHttp = 'http://127.0.0.1'
const endpointWs = 'ws://127.0.0.1'
const logoURL = 'http://image-url.com'
const name = 'Test Subnet'
const subnetId = ethers.utils.formatBytes32String('subnetId')
const subnetId = ethers.encodeBytes32String('subnetId')

async function deploySubnetRegistratorFixture() {
const [admin, nonAdmin, toposDeployer] = await ethers.getSigners()
const SubnetRegistrator = await ethers.getContractFactory(
'SubnetRegistrator'
)
subnetRegistrator = await SubnetRegistrator.connect(toposDeployer).deploy()
await subnetRegistrator.deployed()
const subnetRegistrator = await new SubnetRegistrator__factory(
toposDeployer
).deploy()
await subnetRegistrator.waitForDeployment()
await subnetRegistrator.initialize(admin.address)
return {
admin,
Expand Down Expand Up @@ -177,7 +177,8 @@ describe('SubnetRegistrator', () => {

describe('removeSubnet', () => {
it('reverts if non-admin tries to remove a subnet', async () => {
const [, nonAdmin] = await ethers.getSigners()
const { nonAdmin, subnetRegistrator } =
await deploySubnetRegistratorFixture()
await expect(
subnetRegistrator.connect(nonAdmin).removeSubnet(subnetId)
).to.be.revertedWith('Ownable: caller is not the owner')
Expand Down Expand Up @@ -212,15 +213,15 @@ describe('SubnetRegistrator', () => {
})

async function registerSubnet(
admin: Wallet,
admin: Signer,
chainId: number,
currencySymbol: string,
endpointHttp: string,
endpointWs: string,
logoURL: string,
name: string,
subnetId: string,
subnetRegistrator: Contract
subnetRegistrator: SubnetRegistrator
) {
return await subnetRegistrator
.connect(admin)
Expand All @@ -237,8 +238,8 @@ describe('SubnetRegistrator', () => {

async function removeSubnet(
subnetId: string,
subnetRegistrator: Contract,
admin: Wallet
subnetRegistrator: SubnetRegistrator,
admin: Signer
) {
return await subnetRegistrator.connect(admin).removeSubnet(subnetId)
}
Expand Down
Loading

0 comments on commit 45d0fe0

Please sign in to comment.