Skip to content

Commit

Permalink
Merge pull request #27 from daostack/test-cases
Browse files Browse the repository at this point in the history
Test cases
  • Loading branch information
ben-kaufman authored Dec 27, 2018
2 parents 2475f97 + 78bc364 commit 5ef08f7
Show file tree
Hide file tree
Showing 8 changed files with 897 additions and 5,588 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"env": {
"amd": true,
"node": true,
"es6": true,
"es6": true
},
"rules": {
"eol-last": 2,
Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ migrationBaseResult.base.GenesisProtocol // migrated genesis protocol address
// migrate an example DAO (requires an existing `output` file with a base migration)
const migrationDAOResult = await DAOstackMigration.migrateDAO(options);
migrationDAOResult.dao.Avatar // DAO avatar address
// migrate both base and an example DAO
// migrate an demo test scenario (requires an existing `output` file with a base migration)
const migrationDemoResult = await DAOstackMigration.migrateDemoTest(options);
migrationDemoResult.test.Avatar // Test DAO avatar address
// migrate base, example DAO and demo test contracts
const migrationResult = await DAOstackMigration.migrate(options); // migrate

// run the cli
Expand Down Expand Up @@ -146,7 +149,14 @@ Example migration result object:
"Avatar": "0x123...",
"NativeToken": "0x123...",
"NativeReputation": "0x123..."
}
},
"test": {
"name": "0x123...",
"Avatar": "0x123...",
"NativeToken": "0x123...",
"NativeReputation": "0x123...",
"proposalId": "0xabc..."
}
}
```

Expand Down
2 changes: 2 additions & 0 deletions migrate-dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ async function migrateDAO ({ web3, spinner, confirm, opts, migrationParams, logT
uController,
cap
)

const Avatar = await forgeOrg.call()
tx = await forgeOrg.send()
await logTx(tx, 'Created new organization.')

spinner.start('Setting AbsoluteVote parameters...')

const absoluteVoteSetParams = absoluteVote.methods.setParameters(
migrationParams.AbsoluteVote.votePerc,
migrationParams.AbsoluteVote.ownerVote
Expand Down
344 changes: 344 additions & 0 deletions migrate-demo-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,344 @@
async function assignGlobalVariables (web3, spinner, opts, logTx, base) {
this.web3 = web3
this.spinner = spinner
this.opts = opts
this.logTx = logTx
this.base = base
}

async function migrateDemoTest ({ web3, spinner, confirm, opts, migrationParams, logTx, previousMigration: { base } }) {
if (!(await confirm('About to migrate new Demo Test. Continue?'))) {
return
}

assignGlobalVariables(web3, spinner, opts, logTx, base)

if (!base) {
const msg = `Couldn't find existing base migration ('migration.json' > 'base').`
this.spinner.fail(msg)
throw new Error(msg)
}

this.spinner.start('Migrating Demo Test...')

let accounts = this.web3.eth.accounts.wallet

if (accounts[1] === undefined) {
this.web3.eth.accounts.wallet.add(this.web3.eth.accounts.privateKeyToAccount(
'0x6cbed15c793ce57650b9877cf6fa156fbef513c4e6134f022a85b1ffdd59b2a1'
))
this.web3.eth.accounts.wallet.add(this.web3.eth.accounts.privateKeyToAccount(
'0x6370fd033278c143179d81c5526140625662b8daa446c22ee2d73db3707e620c'
))
accounts = this.web3.eth.accounts.wallet
}

const externalTokenAddress = await migrateExternalToken()

const [orgName, tokenName, tokenSymbol, founders, tokenDist, repDist, cap] = [
'Genesis Test',
'Genesis Test',
'GDT',
migrationParams.founders.map(({ address }) => address),
migrationParams.founders.map(({ tokens }) => tokens),
migrationParams.founders.map(({ reputation }) => reputation),
'0'
]

const avatarAddress = await migrateDemoDao(orgName, tokenName, tokenSymbol, founders, tokenDist, repDist, cap)

const gpParamsHash = await setGenesisProtocolParams()

const crParamsHash = await setContributionRewardParams(gpParamsHash) // FIXME

const schemes = [
{
address: this.base.ContributionReward,
params: crParamsHash,
permissions: '0x00000000' /* no special params */
}
]

await setSchemes(schemes, avatarAddress)

const [PASS, FAIL] = [1, 2]

const proposalId = await submitProposal({
avatarAddress: avatarAddress,
descHash: '0x000000000000000000000000000000000000000000000000000000000000abcd',
rep: 10,
tokens: 10,
eth: 10,
external: 10,
periodLength: 0,
periods: 1,
beneficiary: accounts[1].address,
externalTokenAddress: externalTokenAddress
})

await voteOnProposal({
proposalId: proposalId,
outcome: FAIL,
voter: accounts[2].address
})

await voteOnProposal({
proposalId: proposalId,
outcome: PASS,
voter: accounts[1].address
})

const avatar = new this.web3.eth.Contract(
require('@daostack/arc/build/contracts/Avatar.json').abi,
avatarAddress,
this.opts
)

const Avatar = avatarAddress
const NativeToken = await avatar.methods.nativeToken().call()
const NativeReputation = await avatar.methods.nativeReputation().call()

return {
test: {
name: orgName,
Avatar,
NativeToken,
NativeReputation,
proposalId
}
}
}

async function migrateExternalToken () {
this.spinner.start('Migrating External Token...')

const externalToken = await new this.web3.eth.Contract(
require('@daostack/arc/build/contracts/DAOToken.json').abi,
undefined,
this.opts
).deploy({
data: require('@daostack/arc/build/contracts/DAOToken.json').bytecode,
arguments: ['External', 'EXT', 0]
}).send()

return externalToken.options.address
}

async function migrateDemoDao (orgName, tokenName, tokenSymbol, founders, tokenDist, repDist, cap) {
this.spinner.start('Creating a new organization...')

const {
UController,
DaoCreator
} = this.base

let tx

const daoCreator = new this.web3.eth.Contract(
require('@daostack/arc/build/contracts/DaoCreator.json').abi,
DaoCreator,
this.opts
)

const forge = daoCreator.methods.forgeOrg(
orgName,
tokenName,
tokenSymbol,
founders,
tokenDist,
repDist,
UController,
cap
)

const avatarAddress = await forge.call()
tx = await forge.send()
await this.logTx(tx, 'Created new organization.')

return avatarAddress
}

async function setContributionRewardParams (gpParamsHash) {
this.spinner.start('Setting Contribution Reward Parameters...')

const {
ContributionReward,
GenesisProtocol
} = this.base

let tx

const contributionReward = new this.web3.eth.Contract(
require('@daostack/arc/build/contracts/ContributionReward.json').abi,
ContributionReward,
this.opts
)

const crParams = {
orgNativeTokenFeeGWei: 0
}

const crSetParams = contributionReward.methods.setParameters(
this.web3.utils.toWei(crParams.orgNativeTokenFeeGWei.toString(), 'gwei'),
gpParamsHash,
GenesisProtocol
)

const crParamsHash = await crSetParams.call()
tx = await crSetParams.send()
await this.logTx(tx, 'Contribution Reward Set Parameters.')

return crParamsHash
}

async function setGenesisProtocolParams () {
this.spinner.start('Setting Genesis Protocol Parameters...')

const {
GenesisProtocol
} = this.base

let tx

const genesisProtocol = new this.web3.eth.Contract(
require('@daostack/arc/build/contracts/GenesisProtocol.json').abi,
GenesisProtocol,
this.opts
)

const gpParams = {
boostedVotePeriodLimit: 259200,
daoBountyConst: 75,
daoBountyLimitGWei: 100,
minimumStakingFeeGWei: 0,
preBoostedVotePeriodLimit: 1814400,
preBoostedVoteRequiredPercentage: 50,
proposingRepRewardConstA: 5,
proposingRepRewardConstB: 5,
quietEndingPeriod: 86400,
stakerFeeRatioForVoters: 50,
thresholdConstAGWei: 7,
thresholdConstB: 3,
voteOnBehalf: '0x0000000000000000000000000000000000000000',
votersGainRepRatioFromLostRep: 80,
votersReputationLossRatio: 1
}

const gpSetParams = genesisProtocol.methods.setParameters(
[
gpParams.preBoostedVoteRequiredPercentage,
gpParams.preBoostedVotePeriodLimit,
gpParams.boostedVotePeriodLimit,
this.web3.utils.toWei(gpParams.thresholdConstAGWei.toString(), 'gwei'),
gpParams.thresholdConstB,
this.web3.utils.toWei(gpParams.minimumStakingFeeGWei.toString(), 'gwei'),
gpParams.quietEndingPeriod,
gpParams.proposingRepRewardConstA,
gpParams.proposingRepRewardConstB,
gpParams.stakerFeeRatioForVoters,
gpParams.votersReputationLossRatio,
gpParams.votersGainRepRatioFromLostRep,
gpParams.daoBountyConst,
this.web3.utils.toWei(gpParams.daoBountyLimitGWei.toString(), 'gwei')
],
gpParams.voteOnBehalf
)

const gpParamsHash = await gpSetParams.call()

tx = await gpSetParams.send()
await this.logTx(tx, 'Genesis Protocol Set Parameters.')

return gpParamsHash
}

async function setSchemes (schemes, avatarAddress) {
this.spinner.start('Registering Schemes to DAO...')

const {
DaoCreator
} = this.base

let tx

const daoCreator = new this.web3.eth.Contract(
require('@daostack/arc/build/contracts/DaoCreator.json').abi,
DaoCreator,
this.opts
)

tx = await daoCreator.methods.setSchemes(
avatarAddress,
schemes.map(({ address }) => address),
schemes.map(({ params }) => params),
schemes.map(({ permissions }) => permissions)
).send()

await this.logTx(tx, 'Dao Creator Set Schemes.')
}

async function submitProposal ({
avatarAddress,
descHash,
rep,
tokens,
eth,
external,
periodLength,
periods,
beneficiary,
externalTokenAddress
}) {
this.spinner.start('Submitting a new Proposal...')

const {
ContributionReward
} = this.base

let tx

const contributionReward = new this.web3.eth.Contract(
require('@daostack/arc/build/contracts/ContributionReward.json').abi,
ContributionReward,
this.opts
)

const prop = contributionReward.methods.proposeContributionReward(
avatarAddress,
descHash,
rep,
[tokens, eth, external, periodLength, periods],
externalTokenAddress,
beneficiary
)

const proposalId = await prop.call()
tx = await prop.send()
await this.logTx(tx, 'Submit new Proposal.')

return proposalId
}

async function voteOnProposal ({ proposalId, outcome, voter }) {
this.spinner.start('Voting on proposal...')

const {
GenesisProtocol
} = this.base

let tx

const genesisProtocol = new this.web3.eth.Contract(
require('@daostack/arc/build/contracts/GenesisProtocol.json').abi,
GenesisProtocol,
this.opts
)

tx = await genesisProtocol.methods
.vote(proposalId, outcome, voter)
.send({ from: voter })

await this.logTx(tx, 'Voted on Proposal.')
}

module.exports = migrateDemoTest
Loading

0 comments on commit 5ef08f7

Please sign in to comment.