-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
future-apps/payroll/test/contracts/Payroll_upgrade.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const TruffleConfig = require('truffle-config') | ||
const TruffleContract = require('truffle-contract') | ||
const VersionedContractsProvider = require('@aragon/test-helpers/lib/VersionedContractsProvider')(web3, TruffleContract, TruffleConfig) | ||
|
||
contract('Payroll previous version', ([whatever]) => { | ||
it.only('previous version should allow to call isAllowedToken when not initialized', async () => { | ||
const commit = 'aff584ec78545cfb71415dcf2e56426e17a9f9cd' | ||
const projectDir = 'future-apps/payroll' | ||
const provider = VersionedContractsProvider.fromBranch({ commit, projectDir }) | ||
|
||
const PayrollOld = provider.getContract('Payroll') | ||
const payroll = await PayrollOld.new() | ||
|
||
assert.equal(await payroll.isTokenAllowed(whatever), false, 'should not fail calling to isTokenAllowed without initialization') | ||
}).timeout(1800000) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const { spawnSync } = require('child_process') | ||
|
||
const APPS_GIT_URL = 'https://github.com/aragon/aragon-apps.git' | ||
|
||
module.exports = (web3, TruffleContract, TruffleConfig) => { | ||
return class VersionedContractsProvider { | ||
static fromBranch({ commit, source = APPS_GIT_URL, projectDir = '.', outputDir = 'tmp' }) { | ||
const outputPath = path.resolve(outputDir) | ||
const compiler = new RemoteCompiler(source, commit, projectDir, outputPath) | ||
const buildDirPath = compiler.call() | ||
return new VersionedContractsProvider(buildDirPath) | ||
} | ||
|
||
static fromPath(buildDirPath) { | ||
return new VersionedContractsProvider(buildDirPath) | ||
} | ||
|
||
constructor(buildDirPath) { | ||
this.buildDirPath = buildDirPath | ||
} | ||
|
||
getContract(contractName) { | ||
const path = `${this.buildDirPath}/${contractName}.json` | ||
const contract = TruffleContract(require(path)) | ||
return this._provideContract(contract) | ||
} | ||
|
||
_provideContract(contract) { | ||
contract.setNetwork('test') | ||
contract.defaults(this._getContractsDefaults()) | ||
contract.setProvider(web3.currentProvider) | ||
return contract | ||
} | ||
|
||
_getContractsDefaults() { | ||
const config = TruffleConfig.detect({ logger: console }) | ||
const defaults = this._pickKeys(config, ['from', 'gas', 'gasPrice']) | ||
if (!defaults.from) defaults.from = web3.eth.accounts[0] | ||
return defaults | ||
} | ||
|
||
_pickKeys(object, keys) { | ||
return keys.reduce((result, key) => { | ||
if (object[key] !== undefined) result[key] = object[key] | ||
return result | ||
}, {}) | ||
} | ||
} | ||
} | ||
|
||
class RemoteCompiler { | ||
constructor(source, commit, projectDir, outputPath) { | ||
this.source = source | ||
this.commit = commit | ||
this.outputPath = outputPath | ||
this.projectPath = path.resolve(this.outputPath, projectDir) | ||
} | ||
|
||
call() { | ||
this.cloneGithubRepo() | ||
return this.compile() | ||
} | ||
|
||
cloneGithubRepo() { | ||
if (!fs.existsSync(this.outputPath)) fs.mkdirSync(this.outputPath) | ||
this._run('git', ['clone', this.source, this.outputPath]) | ||
this._run('git', ['reset', '--hard', this.commit], this.outputPath) | ||
} | ||
|
||
compile() { | ||
this._run('npm', ['install'], this.outputPath) | ||
this._run('npx', ['truffle', 'compile'], this.projectPath) | ||
return path.resolve(this.projectPath, 'build/contracts') | ||
} | ||
|
||
_run(cmd, args = [], cwd = '.') { | ||
console.log(`Running ${cmd} with args ${args} in ${cwd}`) | ||
const output = spawnSync(cmd, args, { cwd }) | ||
if (output.error) throw new Error(`Failed running command ${cmd} in ${cwd}: \n${output.error}`) | ||
} | ||
} |