Skip to content

Commit

Permalink
Fixed Votes contract
Browse files Browse the repository at this point in the history
  • Loading branch information
prxgr4mm3r committed Aug 14, 2023
1 parent fc65b02 commit 9e895d4
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 52 deletions.
4 changes: 4 additions & 0 deletions examples/psp22_extensions/votes/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod my_psp22_votes {
},
nonces,
nonces::*,
governor::TimestampProvider,
psp22::extensions::votes::*,
traits::{
errors::GovernanceError,
Expand Down Expand Up @@ -58,6 +59,9 @@ pub mod my_psp22_votes {
}
}

impl TimestampProvider for Contract {
}

impl VotesImpl for Contract {}

impl Votes for Contract {
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"@types/mocha": "^8.0.3",
"@typescript-eslint/eslint-plugin": "^4.8.2",
"@typescript-eslint/parser": "^4.8.2",
"blake2": "github:vrza/node-blake2",
"chai": "^4.3.6",
"chai-as-promised": "^7.1.1",
"eslint": "^7.26.0",
Expand Down
56 changes: 7 additions & 49 deletions tests/e2e/governance/governor.tests.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import {ApiPromise} from '@polkadot/api'
import {bytesToString, getSelectorByName, getSigners, SS58ToHex, Uint8ArrayToString} from '../helpers'
import {getSelectorByName, getSigners, SS58ToHex} from '../helpers'
import ConstructorsGovernance from '../../../typechain-generated/constructors/my_governor'
import ContractGovernance from '../../../typechain-generated/contracts/my_governor'

import ConstructorsReceiver from '../../../typechain-generated/constructors/mock_receiver'
import ContractReceiver from '../../../typechain-generated/contracts/mock_receiver'

import type * as ArgumentTypes from '../../../typechain-generated/types-arguments/my_governor'
import {Transaction, VoteType} from '../../../typechain-generated/types-arguments/my_governor'
import {VoteType} from '../../../typechain-generated/types-arguments/my_governor'

import ConstructorsVotes from '../../../typechain-generated/constructors/my_psp22_votes'
import ContractVotes from '../../../typechain-generated/contracts/my_psp22_votes'
import BN from 'bn.js'
import {expect} from 'chai'
import {ProposalState} from '../../../typechain-generated/types-returns/my_governor'
import {GovernorHelper} from './helper'
import {Keyring} from "@polkadot/keyring";

describe('Governor', function () {

async function setup(
totalSupply = 100000,
votingDelay = 0,
Expand Down Expand Up @@ -153,10 +152,7 @@ describe('Governor', function () {
api,
bob,
deployer,
contractGovernance,
contractAddressGovernance,
contractVotes,
contractAddressVotes,
helper
} = await setup()

Expand All @@ -178,10 +174,7 @@ describe('Governor', function () {
api,
bob,
deployer,
contractGovernance,
contractAddressGovernance,
contractVotes,
contractAddressVotes,
helper
} = await setup()

Expand Down Expand Up @@ -218,12 +211,7 @@ describe('Governor', function () {
it('if proposal does not exist', async function () {
const {
api,
bob,
deployer,
contractGovernance,
contractAddressGovernance,
contractVotes,
contractAddressVotes,
helper
} = await setup()

Expand All @@ -237,8 +225,6 @@ describe('Governor', function () {
api,
bob,
deployer,
contractGovernance,
contractAddressGovernance,
contractVotes,
helper
} = await setup()
Expand All @@ -262,10 +248,7 @@ describe('Governor', function () {
api,
bob,
deployer,
contractGovernance,
contractAddressGovernance,
contractVotes,
contractAddressVotes,
helper
} = await setup()

Expand All @@ -288,10 +271,7 @@ describe('Governor', function () {
api,
bob,
deployer,
contractGovernance,
contractAddressGovernance,
contractVotes,
contractAddressVotes,
helper
} = await setup()

Expand Down Expand Up @@ -323,7 +303,6 @@ describe('Governor', function () {
bob,
deployer,
contractVotes,
contractAddressVotes,
helper
} = await setup()

Expand All @@ -349,12 +328,7 @@ describe('Governor', function () {
it('Unset', async function () {
const {
api,
bob,
deployer,
contractGovernance,
contractAddressGovernance,
contractVotes,
contractAddressVotes,
helper
} = await setup()

Expand All @@ -368,10 +342,7 @@ describe('Governor', function () {
api,
bob,
deployer,
contractGovernance,
contractAddressGovernance,
contractVotes,
contractAddressVotes,
helper
} = await setup()

Expand All @@ -396,10 +367,7 @@ describe('Governor', function () {
api,
bob,
deployer,
contractGovernance,
contractAddressGovernance,
contractVotes,
contractAddressVotes,
helper
} = await setup()

Expand All @@ -423,10 +391,7 @@ describe('Governor', function () {
api,
bob,
deployer,
contractGovernance,
contractAddressGovernance,
contractVotes,
contractAddressVotes,
helper
} = await setup()

Expand Down Expand Up @@ -456,10 +421,7 @@ describe('Governor', function () {
api,
bob,
deployer,
contractGovernance,
contractAddressGovernance,
contractVotes,
contractAddressVotes,
helper
} = await setup()

Expand All @@ -486,10 +448,6 @@ describe('Governor', function () {
const {
api,
deployer,
contractGovernance,
contractAddressGovernance,
contractVotes,
contractAddressVotes,
helper
} = await setup()

Expand Down Expand Up @@ -567,8 +525,8 @@ describe('Governor', function () {
api,
bob,
deployer,
helper,
contractVotes
contractVotes,
helper
} = await setup()

helper.addProposal(
Expand Down Expand Up @@ -702,7 +660,7 @@ describe('Governor', function () {

describe('with proposer suffix but bad address part', function () {
it('propose can propose', async function () {
const {api, helper, deployer, contractGovernance, contractReceiver} = await setup()
const {api, helper, deployer, contractReceiver} = await setup()

helper.addProposal(
contractReceiver.address,
Expand All @@ -717,7 +675,7 @@ describe('Governor', function () {
})

it('someone else can propose', async function () {
const {api, helper, deployer, contractReceiver, alice} = await setup()
const {api, helper, contractReceiver, alice} = await setup()

helper.addProposal(
contractReceiver.address,
Expand Down
50 changes: 48 additions & 2 deletions tests/e2e/governance/votes.tests.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,57 @@
import {ApiPromise} from "@polkadot/api";
import {expect, getSigners} from "../helpers";
import ConstructorsVotes from "../../../typechain-generated/constructors/my_psp22_votes";
import ContractVotes from "../../../typechain-generated/contracts/my_psp22_votes";
import ConstructorsGovernance from "../../../typechain-generated/constructors/my_governor";
import ContractGovernance from "../../../typechain-generated/contracts/my_governor";
import {GovernorHelper} from "./helper";

describe('Votes', function () {

async function setup(
totalSupply = 100000,
votingDelay = 0,
votingPeriod = 10,
proposalThreshold = 0,
numrator = 0
){
const api = await ApiPromise.create()

const signers = getSigners()
const deployer = signers[0]
const alice = signers[1]
const bob = signers[2]
const contractFactoryVotes = new ConstructorsVotes(api, deployer)
const contractAddressVotes = (await contractFactoryVotes.new(totalSupply)).address
const contractVotes = new ContractVotes(contractAddressVotes, deployer, api)

return {
api,
alice,
bob,
deployer,
contractVotes,
contractAddressVotes,
}
}

beforeEach(async function () {
//
})


it('starts with zero votes', async function () {
//
const {
api,
alice,
bob,
deployer,
contractVotes,
contractAddressVotes,
} = await setup()

await expect(contractVotes.query.totalSupply()).to.have.bnToNumber(0)

await api.disconnect()
})

describe('performs voting operations', function () {
Expand Down

0 comments on commit 9e895d4

Please sign in to comment.