Skip to content

Commit

Permalink
fixing tests wip
Browse files Browse the repository at this point in the history
  • Loading branch information
peersky committed Sep 30, 2023
1 parent e7aec5f commit 24e2470
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1421,9 +1421,9 @@
},
{
"indexed": false,
"internalType": "bytes32[]",
"internalType": "bytes32",
"name": "votesHidden",
"type": "bytes32[]"
"type": "bytes32"
},
{
"indexed": false,
Expand Down Expand Up @@ -1559,9 +1559,9 @@
"type": "uint256"
},
{
"internalType": "bytes32[]",
"internalType": "bytes32",
"name": "votesHash",
"type": "bytes32[]"
"type": "bytes32"
},
{
"internalType": "bytes",
Expand Down
8 changes: 4 additions & 4 deletions abi/src/facets/gameMastersFacet.sol/GameMastersFacet.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@
},
{
"indexed": false,
"internalType": "bytes32[]",
"internalType": "bytes32",
"name": "votesHidden",
"type": "bytes32[]"
"type": "bytes32"
},
{
"indexed": false,
Expand Down Expand Up @@ -285,9 +285,9 @@
"type": "uint256"
},
{
"internalType": "bytes32[]",
"internalType": "bytes32",
"name": "votesHash",
"type": "bytes32[]"
"type": "bytes32"
},
{
"internalType": "bytes",
Expand Down
3 changes: 2 additions & 1 deletion deploy/01_deployRankToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
}
const owner = process.env.DAO_CONTRACT_ADDRESS || deployer;

await deploy('RankToken', {
const result = await deploy('RankToken', {
from: deployer,
args: [URI, owner, ContractURI, ethers.BigNumber.from(4)],
skipIfAlreadyDeployed: true,
});
console.log('deployed rank token at', result.address);
};

export default func;
Expand Down
3 changes: 2 additions & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ export default {
},
namedAccounts: {
deployer: {
default: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
default: '0x7231161f85637Dea4DCa51e30ff443eD508c3313',
},
gameOwner: {
hardhat: '0xBfdF0Ee33BF4a2640D67f720Ae6594E81f8114d4',
default: '0xE48BC6673B4EEBec6A230f9112Cb2c1ac17bc273',
},
},
Expand Down
30 changes: 10 additions & 20 deletions test/BestOfGame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,7 @@ const mockValidVotes = async (
if (submitNow) {
votersAddresses = players.map(player => player.wallet.address);
for (let i = 0; i < players.length; i++) {
await env.bestOfGame
.connect(players[i].wallet)
.submitVote(gameId, votes[i].voteHidden, votes[i].proof, votes[i].publicSignature);
await env.bestOfGame.connect(players[i].wallet).submitVote(gameId, votes[i].voteHidden, votes[i].proof);
}
}
return votes;
Expand Down Expand Up @@ -357,9 +355,11 @@ describe(scriptName, () => {
).to.revertedWith('LibDiamond: Must be contract owner');
});
it('has rank token assigned', async () => {
console.log(env.rankToken.address);
const state = await env.bestOfGame.getContractState();
await expect(state.BestOfState.rankTokenAddress).to.be.equal(env.rankToken.address);
expect(await env.rankToken.owner()).to.be.equal(env.bestOfGame.address);
expect(state.BestOfState.rankTokenAddress).to.be.equal(env.rankToken.address);
expect(await env.rankToken.getRankingInstance()).to.be.equal(env.bestOfGame.address);
expect(await env.rankToken.owner()).to.be.equal(adr.contractDeployer.wallet.address);
});
it('Can create game only with valid payments', async () => {
await expect(
Expand Down Expand Up @@ -400,9 +400,7 @@ describe(scriptName, () => {
distribution: 'semiUniform',
});
await expect(
env.bestOfGame
.connect(adr.gameMaster1.wallet)
.submitVote(1, votes[0].voteHidden, votes[0].proof, votes[0].publicSignature),
env.bestOfGame.connect(adr.gameMaster1.wallet).submitVote(1, votes[0].voteHidden, votes[0].proof),
).to.be.revertedWith('no game found');
await expect(env.bestOfGame.connect(adr.gameMaster1.wallet).openRegistration(1)).to.be.revertedWith(
'no game found',
Expand Down Expand Up @@ -559,9 +557,7 @@ describe(scriptName, () => {
),
).to.be.revertedWith('Game has not yet started');
await expect(
env.bestOfGame
.connect(adr.gameMaster1.wallet)
.submitVote(1, votes[0].voteHidden, votes[0].proof, votes[0].publicSignature),
env.bestOfGame.connect(adr.gameMaster1.wallet).submitVote(1, votes[0].voteHidden, votes[0].proof),
).to.be.revertedWith('Game has not yet started');
await expect(env.bestOfGame.connect(adr.gameCreator1.wallet).openRegistration(1)).to.be.revertedWith(
'Cannot do when registration is open',
Expand Down Expand Up @@ -630,9 +626,7 @@ describe(scriptName, () => {
),
).to.be.revertedWith('Game has not yet started');
await expect(
env.bestOfGame
.connect(adr.gameMaster1.wallet)
.submitVote(1, votes[0].voteHidden, votes[0].proof, votes[0].publicSignature),
env.bestOfGame.connect(adr.gameMaster1.wallet).submitVote(1, votes[0].voteHidden, votes[0].proof),
).to.be.revertedWith('Game has not yet started');
});
describe('When game has started', () => {
Expand Down Expand Up @@ -665,9 +659,7 @@ describe(scriptName, () => {
votersAddresses = getPlayers(adr, BOGSettings.BOG_MAX_PLAYERS).map(player => player.wallet.address);

await expect(
env.bestOfGame
.connect(adr.player1.wallet)
.submitVote(1, votes[0].voteHidden, votes[0].proof, votes[0].publicSignature),
env.bestOfGame.connect(adr.player1.wallet).submitVote(1, votes[0].voteHidden, votes[0].proof),
).to.be.revertedWith('No proposals exist at turn 1: cannot vote');
});
it('Processes only proposals only from game master', async () => {
Expand Down Expand Up @@ -1043,9 +1035,7 @@ describe(scriptName, () => {

let name = `player${i + 1}` as any as keyof AdrSetupResult;
await expect(
env.bestOfGame
.connect(adr[`${name}`].wallet)
.submitVote(1, votes[i].voteHidden, votes[i].proof, votes[i].publicSignature),
env.bestOfGame.connect(adr[`${name}`].wallet).submitVote(1, votes[i].voteHidden, votes[i].proof),
).to.be.revertedWith('Game over');
}
await expect(
Expand Down
2 changes: 1 addition & 1 deletion test/RankToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('Rank Token Test', async function () {
it('reports correct balance of unlocked', async () => {
expect(
(await env.connect(adr.maliciousActor1.wallet).balanceOfUnlocked(adr.player1.wallet.address, 1)).toNumber(),
).to.be.equal(2);
).to.be.equal(2);
});
it('Can be unlocked only by a rankingInstance', async () => {
await expect(env.connect(rankingInstance).unlockFromInstance(adr.player1.wallet.address, 1, 1))
Expand Down
11 changes: 6 additions & 5 deletions test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import { ProposalTypes } from '../types';
const { ZERO_ADDRESS, ZERO_BYTES32 } = require('@openzeppelin/test-helpers/src/constants');
import { BigNumber, BigNumberish, Bytes, BytesLike, Wallet } from 'ethers';
// @ts-ignore
import { RankToken } from '../types/typechain/contracts/tokens/RankToken';
// import { BestOfInit } from "../types/typechain/contracts/initializers/BestOfInit";
import { RankToken } from '../types/typechain/src/tokens/RankToken';
// import { BestOfInit } from "../types/typechain/src/initializers/BestOfInit";
import { assert } from 'console';
import { Deployment } from 'hardhat-deploy/types';
import { HardhatEthersHelpers } from '@nomiclabs/hardhat-ethers/types';
import { keccak256 } from 'ethers/lib/utils';

export interface SignerIdentity {
name: string;
Expand Down Expand Up @@ -611,7 +612,7 @@ export const getPlayers = (
export type MockVotes = Array<{
proof: string;
vote: [BigNumberish, BigNumberish, BigNumberish];
voteHidden: [BytesLike, BytesLike, BytesLike];
voteHidden: string;
publicSignature: string;
}>;

Expand All @@ -633,7 +634,7 @@ export const mockVotes = async ({
const votes: Array<{
proof: string;
vote: [BigNumberish, BigNumberish, BigNumberish];
voteHidden: [BytesLike, BytesLike, BytesLike];
voteHidden: string;
publicSignature: string;
}> = [];
for (let k = 0; k < players.length; k++) {
Expand Down Expand Up @@ -688,7 +689,7 @@ export const mockVotes = async ({
verifierAddress,
vote: [firstSelected, secondSelected, thirdSelected],
});
votes[k] = { vote, voteHidden, proof, publicSignature };
votes[k] = { vote, voteHidden: keccak256(JSON.stringify(voteHidden)), proof, publicSignature };
}
return votes;
};
Expand Down

0 comments on commit 24e2470

Please sign in to comment.