Skip to content

Commit

Permalink
chore: fix workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
geolffreym committed Jul 30, 2024
1 parent f659c07 commit 38fb701
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 253 deletions.
9 changes: 0 additions & 9 deletions .github/workflows/static-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@ on:
pull_request:

jobs:
lint:
name: eslint linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npm install standard
- run: make lint

solhint:
name: solhint linting
runs-on: ubuntu-latest
Expand Down
12 changes: 5 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ ifneq (,$(wildcard ./.env))
endif

.DEFAULT_GOAL := all
stage=development
region=us-west-2
function=graphql
network=hardhat

.PHONY: bootstrap ## setup initial development environment
bootstrap: install
Expand All @@ -17,7 +15,7 @@ bootstrap: install
# https://jestjs.io/docs/cli#--coverageboolean
.PHONY: test ## run tests
test:
@npx hardhat test
@npx hardhat test --network $(network)

.PHONY: testcov ## run tests coverage report
testcov:
Expand All @@ -39,11 +37,11 @@ install:

.PHONY: format ## auto-format js source files
format:
@npx standard --fix
@npx ts-standard --fix

.PHONY: lint ## lint standard js
lint:
@npx standard
@npx ts-standard

.PHONY: solformat ## auto-format solidity source files
solformat:
Expand Down Expand Up @@ -75,7 +73,7 @@ keysenv:

.PHONY: amoydeploy ## deploy contract to amoy network
amoydeploy:
@npx harhat deploy
@npx harhat deploy --network $(network)

rebuild: clean
all: test lint
Expand Down
31 changes: 13 additions & 18 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import dotenv from 'dotenv'
import type { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-chai-matchers";
import "@nomicfoundation/hardhat-toolbox";
import "@openzeppelin/hardhat-upgrades"
import type { HardhatUserConfig } from 'hardhat/config'
import '@nomicfoundation/hardhat-chai-matchers'
import '@nomicfoundation/hardhat-toolbox'
import '@openzeppelin/hardhat-upgrades'
import '@typechain/hardhat'

dotenv.config()
const OWNER_KEY = process.env.PK
const ALCHEMY_API_KEY = process.env.ALCHEMY_API_KEY
const HARDHAT_AUTOMINE = process.env.HARDHAT_AUTOMINE

if (HARDHAT_AUTOMINE === 'true' && !process.env.CI) {
console.warn('WARN: HARDHAT_AUTOMINE is on. This should only be in CI or selectively on local')
}
const OWNER_KEY = process.env.PK ?? ''
const ALCHEMY_API_KEY = process.env.ALCHEMY_API_KEY ?? ''

const config: HardhatUserConfig = {
solidity: {
Expand All @@ -21,14 +16,14 @@ const config: HardhatUserConfig = {
viaIR: true,
optimizer: {
enabled: true,
runs: 200
},
runs: 500
}
}
},
gasReporter: {
currency: 'USD',
showTimeSpent: true,
L1: "polygon",
L1: 'polygon',
enabled: true,
coinmarketcap: '6ffc3d5b-865e-482d-a05c-144ba7fe319e'
},
Expand All @@ -37,18 +32,18 @@ const config: HardhatUserConfig = {
},
networks: {
hardhat: {
chainId: 31337,
throwOnTransactionFailures: true,
throwOnCallFailures: true
},
polygon: {
url: `https://polygon-amoy.g.alchemy.com/v2/${ALCHEMY_API_KEY}`,
accounts: [`0x${OWNER_KEY}`],
accounts: [`${OWNER_KEY}`]
}
},
mocha: {
timeout: 40000
timeout: 0
}
}


export default config;
export default config
26 changes: 13 additions & 13 deletions ignition/modules/Lock.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
import { parseEther } from "viem";
import { buildModule } from '@nomicfoundation/hardhat-ignition/modules'
import { parseEther } from 'viem'

const JAN_1ST_2030 = 1893456000;
const ONE_GWEI: bigint = parseEther("0.001");
const JAN_1ST_2030 = 1893456000
const ONE_GWEI: bigint = parseEther('0.001')

const LockModule = buildModule("LockModule", (m) => {
const unlockTime = m.getParameter("unlockTime", JAN_1ST_2030);
const lockedAmount = m.getParameter("lockedAmount", ONE_GWEI);
const LockModule = buildModule('LockModule', (m) => {
const unlockTime = m.getParameter('unlockTime', JAN_1ST_2030)
const lockedAmount = m.getParameter('lockedAmount', ONE_GWEI)

const lock = m.contract("Lock", [unlockTime], {
value: lockedAmount,
});
const lock = m.contract('Lock', [unlockTime], {
value: lockedAmount
})

return { lock };
});
return { lock }
})

export default LockModule;
export default LockModule
114 changes: 53 additions & 61 deletions test/Distributor.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
import hre from "hardhat";
import { expect } from "chai";
import { loadFixture } from "@nomicfoundation/hardhat-toolbox/network-helpers";
import { Distributor, DistributorFactory } from "@/typechain-types";
import hre from 'hardhat'
import { expect } from 'chai'
import { switcher } from './helpers/CommonHelper'
import { Distributor } from '@/typechain-types'
import {
deployDistributorFactory,
getFilterLastEventArgs,
commitRegister,
deployAndInitializeDistributorContract
} from './helpers/DistributorHelper';
} from './helpers/DistributorHelper'

const DISTRIBUTOR_INTERFACE_ID = "0x27d9e1cd"
const DISTRIBUTOR_INTERFACE_ID = '0x27d9e1cd'

async function getAccounts() {
async function getAccounts (): Promise<hre.ethers.HardhatEthersSigner[]> {
return await hre.ethers.getSigners()
}

describe("Distributor", function () {

describe("Beacon", function () {

describe('Distributor', function () {
describe('Beacon', function () {
it("Should create a valid 'Distributor'.", async function () {
const beacon = await loadFixture(deployDistributorFactory)
const beacon = await switcher(deployDistributorFactory)
const beaconProxy = await commitRegister(beacon, 'watchit.movie')
// attach to distributor beacon proxy
const contractFactory = await hre.ethers.getContractFactory("Distributor")
const contractFactory = await hre.ethers.getContractFactory('Distributor')
const distributor = contractFactory.attach(beaconProxy) as Distributor

expect(await distributor.supportsInterface(DISTRIBUTOR_INTERFACE_ID)).to.be.true
expect(await distributor.getEndpoint()).to.be.equal("watchit.movie")
expect(await distributor.getEndpoint()).to.be.equal('watchit.movie')
})

it("Should add a new contract to 'contracts' list.", async function () {
const beacon = (await loadFixture(deployDistributorFactory)) as DistributorFactory
const beacon = (await switcher(deployDistributorFactory)) as DistributorFactory
const beaconProxy1 = await commitRegister(beacon, 'watchit.movie')
const beaconProxy2 = await commitRegister(beacon, 'watchit2.movie')

Expand All @@ -41,37 +39,35 @@ describe("Distributor", function () {

expect(contract1).to.equal(beaconProxy1)
expect(contract2).to.equal(beaconProxy2)
});
})

it("Should add the distributor correctly in registry mapping.", async function () {
it('Should add the distributor correctly in registry mapping.', async function () {
const registeredDomain = 'watchit.movie'
const beacon = await loadFixture(deployDistributorFactory)
const [owner,] = await hre.ethers.getSigners();
const beacon = await switcher(deployDistributorFactory)
const [owner] = await hre.ethers.getSigners()

await commitRegister(beacon, registeredDomain)
const registeredOwner = await beacon.registry(registeredDomain)
expect(registeredOwner).to.be.equal(owner)
})


it("Should fail if domain is already registered.", async function () {
it('Should fail if domain is already registered with DistributorAlreadyRegistered.', async function () {
const duplicatedDomain = 'watchit.movie'
const beacon = await loadFixture(deployDistributorFactory)
const beacon = await switcher(deployDistributorFactory)

await commitRegister(beacon, duplicatedDomain)
await expect(beacon.register(duplicatedDomain)).to.be.revertedWithCustomError(
beacon, "DistributorAlreadyRegistered"
);

beacon, 'DistributorAlreadyRegistered'
)
})

it("Should emit a valid 'DistributorCreated' after register distributor.", async function () {
const beacon = await loadFixture(deployDistributorFactory)
it('Should emit a valid DistributorCreated after register distributor.', async function () {
const beacon = await switcher(deployDistributorFactory)
expect(beacon.register('watchit.movie')).to.emit(beacon, 'DistributorCreated')
})

it("Should pause/unpause properly.", async function () {
const beacon = await loadFixture(deployDistributorFactory)
it('Should pause/unpause properly.', async function () {
const beacon = await switcher(deployDistributorFactory)
const pause = await beacon.pause()
await pause.wait()
expect(await beacon.paused()).to.be.true
Expand All @@ -80,58 +76,54 @@ describe("Distributor", function () {
await unpause.wait()
expect(await beacon.paused()).to.be.false
})
});

describe("Implementation", function () {
})

describe('Implementation', function () {
it("Should implement a valid 'Distributor'.", async function () {
const distributor = await deployAndInitializeDistributorContract("watchit.com")
const distributor = await deployAndInitializeDistributorContract('watchit.com')
expect(await distributor.supportsInterface(DISTRIBUTOR_INTERFACE_ID)).to.be.true
})

it("Should update a valid endpoint successfully.", async function () {
const newEndpoint = 'watchit4.movie';
it('Should update a valid endpoint successfully.', async function () {
const newEndpoint = 'watchit4.movie'
// initial endpoint set by beacon proxy initialization.
const distributor = await deployAndInitializeDistributorContract("watchit.com")
const updater = await distributor.updateEndpoint(newEndpoint);
await updater.wait();
const distributor = await deployAndInitializeDistributorContract('watchit.com')
const updater = await distributor.updateEndpoint(newEndpoint)
await updater.wait()

const distributorEndpoint = await distributor.getEndpoint()
expect(newEndpoint).to.be.equal(distributorEndpoint);

});
expect(newEndpoint).to.be.equal(distributorEndpoint)
})

it("Should emit a valid EndpointUpdated after update endpoint.", async function () {
const newEndpoint = 'watchit3.movie';
const distributor = await deployAndInitializeDistributorContract("watchit.movie")
const updater = await distributor.updateEndpoint(newEndpoint);
await updater.wait();
it('Should emit a valid EndpointUpdated after update endpoint.', async function () {
const newEndpoint = 'watchit3.movie'
const distributor = await deployAndInitializeDistributorContract('watchit.movie')
const updater = await distributor.updateEndpoint(newEndpoint)
await updater.wait()

const filter = distributor.filters.EndpointUpdated()
const lastEvent = await getFilterLastEventArgs(distributor, filter)
const old = lastEvent?.oldEndpoint.toString()
const new_ = lastEvent?.newEndpoint.toString()

expect(updater).to.emit(distributor, 'EndpointUpdated')
expect(old).to.be.equal("watchit.movie");
expect(new_).to.be.equal("watchit3.movie");

});
expect(old).to.be.equal('watchit.movie')
expect(new_).to.be.equal('watchit3.movie')
})

it("Should fail if `updateEndpoint` is called with invalid empty endpoint.", async function () {
const distributor = await deployAndInitializeDistributorContract("watchit.movie")
it('Should fail if `updateEndpoint` is called with invalid empty endpoint.', async function () {
const distributor = await deployAndInitializeDistributorContract('watchit.movie')
await expect(distributor.updateEndpoint('')).to.be.revertedWithCustomError(
distributor, "InvalidEndpoint"
);
distributor, 'InvalidEndpoint'
)
})

it("Should fail if `updateEndpoint` is called with invalid owner.", async function () {
const [, secondary] = await loadFixture(getAccounts)
const distributor = await deployAndInitializeDistributorContract("watchit.movie")
it('Should fail if `updateEndpoint` is called with invalid owner.', async function () {
const [, secondary] = await switcher(getAccounts)
const distributor = await deployAndInitializeDistributorContract('watchit.movie')
await expect(distributor.connect(secondary).updateEndpoint('check.com')).to.be.revertedWithCustomError(
distributor, "OwnableUnauthorizedAccount"
);
distributor, 'OwnableUnauthorizedAccount'
)
})
})

});
})
Loading

0 comments on commit 38fb701

Please sign in to comment.