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

test: airdrop of BB #104

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import './tasks/cancelProposal'
import './tasks/withdrawTreasury'
import './tasks/airdrop'
import './tasks/stRifUpgradeV1-v2'
import './tasks/ownerships'

dotent.config()

Expand Down
2 changes: 1 addition & 1 deletion ignition/modules/BetaBuildersModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const betaBuildersModule = buildModule('BetaBuilders', m => {
// deploy implementation
const implementation = m.contract('BetaBuildersRootstockCollective', [], { id: 'Implementation' })

const deployer = m.getAccount(0)
const deployer = m.getParameter('deployer')
// deploy proxy
const proxy = m.contract('ERC1967Proxy', [
implementation,
Expand Down
22 changes: 0 additions & 22 deletions params/BetaBuildersModule/airdrop-testnet.json

This file was deleted.

27 changes: 27 additions & 0 deletions params/BetaBuildersModule/params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"BetaBuilders": {
"deployer": "0x0C48e53E5852780Cb0a5Bf168eb92DE3B88Ebe89",
"receivers": [
{
"receiver": "0x0C48e53E5852780Cb0a5Bf168eb92DE3B88Ebe89",
"ipfsCid": "bafybeiabgvm3zylkuj24ukfa4aimh3g3nryivhuqr6ztczjlbhqbt3flvm/1.json"
},
{
"receiver": "0x81DF35317dF983E419630908eF6Cb2Bb48CE21Ca",
"ipfsCid": "bafybeiabgvm3zylkuj24ukfa4aimh3g3nryivhuqr6ztczjlbhqbt3flvm/2.json"
},
{
"receiver": "0x55A6AA81f8f89e1C14482CE3a6Fb40bAB57971B5",
"ipfsCid": "bafybeiabgvm3zylkuj24ukfa4aimh3g3nryivhuqr6ztczjlbhqbt3flvm/3.json"
},
{
"receiver": "0x61cB47ea86430e40Ac1128eA4BC28dEAB66554D5",
"ipfsCid": "bafybeiabgvm3zylkuj24ukfa4aimh3g3nryivhuqr6ztczjlbhqbt3flvm/4.json"
},
{
"receiver": "0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc",
"ipfsCid": "bafybeiabgvm3zylkuj24ukfa4aimh3g3nryivhuqr6ztczjlbhqbt3flvm/5.json"
}
]
}
}
9 changes: 9 additions & 0 deletions tasks/addresses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"addresses": [
"0x0C48e53E5852780Cb0a5Bf168eb92DE3B88Ebe89",
"0x81DF35317dF983E419630908eF6Cb2Bb48CE21Ca",
"0x55A6AA81f8f89e1C14482CE3a6Fb40bAB57971B5",
"0x61cB47ea86430e40Ac1128eA4BC28dEAB66554D5",
"0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc"
]
}
12 changes: 7 additions & 5 deletions tasks/airdrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@ async function airdrop(hre: HardhatRuntimeEnvironment, nftAddress: string, recei

interface Parameters {
nft: string
receivers: string
airdropped: string
}

task('airdrop', 'Execute NFT airdrop')
.addParam('nft', 'NFT smart contract address')
.addParam('receivers', 'JSON file with a list of token receiver addresses and corresponding IPFS CIDs')
.setAction(async ({ nft, receivers }: Parameters, hre) => {
.addParam('airdropped', 'JSON file with a list of token receiver addresses and corresponding IPFS CIDs')
.setAction(async ({ nft, airdropped }: Parameters, hre) => {
try {
const airdropReceivers: AirdropRecipient[] = await fs.readJson(receivers)
airdrop(hre, nft, airdropReceivers)
const {
BetaBuilders: { receivers },
}: { BetaBuilders: { receivers: AirdropRecipient[] } } = await fs.readJson(airdropped)
await airdrop(hre, nft, receivers)
console.log('Airdrop was executed')
} catch (error) {
console.log(error instanceof Error ? error.message : error)
Expand Down
42 changes: 42 additions & 0 deletions tasks/ownerships.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { task } from 'hardhat/config'
import fs from 'fs-extra'
import { BetaBuildersRootstockCollective } from '../typechain-types'

// BetaBuilders#Implementation - 0x3D584161A15CE982eE339cbC28ebb0e1E535A7D3
// BetaBuilders#ERC1967Proxy - 0xc9B3346a3f151090130b63A28D35875F3C2d6a4d
// BetaBuilders#Contract - 0xc9B3346a3f151090130b63A28D35875F3C2d6a4d

interface Parameters {
addresses: string
}

async function checkCorrectOwnerships(contract: BetaBuildersRootstockCollective, addresses: string[]) {
return await Promise.all(
addresses.map(async (addr, i) => {
return addr === (await contract.ownerOf(i + 1))
}),
)
}

task('ownerships', 'It will check ownerships of airdropped NFTs')
.addParam('addresses', 'Path to JSON file with addresses')
.setAction(async ({ addresses }: Parameters, hre) => {
try {
const contract = await hre.ethers.getContractAt(
'BetaBuildersRootstockCollective',
'0xc9B3346a3f151090130b63A28D35875F3C2d6a4d',
)

const totalSupply = await contract.totalSupply()

console.log('totalSupply', totalSupply)

const checkAddresses: { addresses: string[] } = await fs.readJson(addresses)
console.log('checkAddresses', checkAddresses)
const areTheyOwners = await checkCorrectOwnerships(contract, checkAddresses.addresses)

console.log('Ownership results:', areTheyOwners)
} catch (error) {
console.error(error instanceof Error ? error.message : error)
}
})
33 changes: 21 additions & 12 deletions test/BetaBuilders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import hre, { ethers, ignition } from 'hardhat'
import { BetaBuildersRootstockCollective } from '../typechain-types'
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'
import { betaBuildersModule } from '../ignition/modules/BetaBuildersModule'
import airdropReceivers from '../params/BetaBuildersModule/airdrop-testnet.json'
import { BetaBuilders } from '../params/BetaBuildersModule/params.json'
import { setBalance } from '@nomicfoundation/hardhat-network-helpers'

describe('BetaBuildersRootstockCollective NFT', () => {
let deployer: SignerWithAddress
Expand All @@ -13,15 +14,23 @@ describe('BetaBuildersRootstockCollective NFT', () => {

before(async () => {
;[deployer, alice] = await ethers.getSigners()
const contract = await ignition.deploy(betaBuildersModule)
const contract = await ignition.deploy(betaBuildersModule, {
parameters: {
BetaBuilders: {
deployer: deployer.address,
},
},
})
betaBuildersEP = contract.ExtBetaBuildersEP as unknown as BetaBuildersRootstockCollective
// impersonating airdrop receivers
for (let i = 0; i < airdropReceivers.length; i++) {
const accountAddr = airdropReceivers[i].receiver
for (let i = 0; i < BetaBuilders.receivers.length; i++) {
const accountAddr = BetaBuilders.receivers[i].receiver
await hre.network.provider.request({
method: 'hardhat_impersonateAccount',
params: [accountAddr],
})

await setBalance(accountAddr, ethers.parseEther('2'))
const account = await ethers.getSigner(accountAddr)
oldGangsters.push(account)
}
Expand All @@ -44,9 +53,9 @@ describe('BetaBuildersRootstockCollective NFT', () => {

describe('Airdrop', () => {
it('should execute the initial airdrop after deployment', async () => {
await expect(betaBuildersEP.connect(deployer).airdrop(airdropReceivers))
await expect(betaBuildersEP.connect(deployer).airdrop(BetaBuilders.receivers))
.to.emit(betaBuildersEP, 'AirdropExecuted')
.withArgs(airdropReceivers.length)
.withArgs(BetaBuilders.receivers.length)
})
it('the Gangsters should own NFTs after the airdrop', async () => {
await Promise.all(
Expand All @@ -58,26 +67,26 @@ describe('BetaBuildersRootstockCollective NFT', () => {
)
})
it('should top up total supply after the airdrop', async () => {
expect(await betaBuildersEP.totalSupply()).to.equal(airdropReceivers.length)
expect(await betaBuildersEP.totalSupply()).to.equal(BetaBuilders.receivers.length)
})
it('non-owner cannot execute airdrop', async () => {
await expect(betaBuildersEP.connect(alice).airdrop(airdropReceivers))
await expect(betaBuildersEP.connect(alice).airdrop(BetaBuilders.receivers))
.to.be.revertedWithCustomError(betaBuildersEP, 'OwnableUnauthorizedAccount')
.withArgs(alice.address)
})
it('should execute the second airdrop to the same addresses', async () => {
await expect(betaBuildersEP.connect(deployer).airdrop(airdropReceivers))
await expect(betaBuildersEP.connect(deployer).airdrop(BetaBuilders.receivers))
.to.emit(betaBuildersEP, 'AirdropExecuted')
.withArgs(airdropReceivers.length)
.withArgs(BetaBuilders.receivers.length)
})
it('the Gangsters should own 2 NFTs after the second airdrop', async () => {
await Promise.all(
oldGangsters.map(async (gangster, i) => {
const tokenId = airdropReceivers.length + i + 1
const tokenId = BetaBuilders.receivers.length + i + 1
expect(await betaBuildersEP.balanceOf(gangster.address)).to.equal(2)
// token IDs: 6, 7, 8...
expect(await betaBuildersEP.tokenOfOwnerByIndex(gangster.address, 1)).to.equal(tokenId)
const cid = airdropReceivers[i].ipfsCid
const cid = BetaBuilders.receivers[i].ipfsCid
expect(await betaBuildersEP.tokenURI(tokenId)).to.equal(`ipfs://${cid}`)
}),
)
Expand Down
Loading
Loading