This repository has been archived by the owner on Jul 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Event parameters should be named: trufflesuite/truffle#494 (comment)
- Loading branch information
Showing
3 changed files
with
88 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
pragma solidity ^0.4.15; | ||
|
||
contract ContractRegistry { | ||
address[] public contracts; | ||
address owner; | ||
address recorder; | ||
|
||
modifier onlyOwner { | ||
require(msg.sender == owner); | ||
_; | ||
} | ||
|
||
modifier onlyRecorder { | ||
require(msg.sender == recorder); | ||
_; | ||
} | ||
|
||
event Added(address contractAddress); | ||
|
||
function getContractsCount() constant returns (uint) { | ||
return contracts.length; | ||
} | ||
|
||
function ContractRegistry() { | ||
owner = msg.sender; | ||
} | ||
|
||
function setRecorder(address _recorder) onlyOwner { | ||
recorder = _recorder; | ||
} | ||
|
||
function add(address _contract) onlyRecorder { | ||
contracts.push(_contract); | ||
Added(_contract); | ||
} | ||
} |
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,46 @@ | ||
/* global artifacts contract it assert */ | ||
|
||
const { assertError } = require('./common'); | ||
|
||
const ContractRegistry = artifacts.require('ContractRegistry'); | ||
|
||
const testContractAddress = '0x7e8a8a78e0938cde6fd89ce47c1319b82d5e4022'; | ||
|
||
contract('ContractRegistry', (accounts) => { | ||
it('can\'t set recorder by not the owner', () => | ||
ContractRegistry.deployed() | ||
.then(instance => instance.setRecorder(accounts[1], { from: accounts[1] })) | ||
.then(assert.fail, assertError)); | ||
|
||
it('set recorder', () => | ||
ContractRegistry.deployed() | ||
.then(instance => instance.setRecorder(accounts[1]))); | ||
|
||
it('can\'t add contract by not the recorder', () => | ||
ContractRegistry.deployed() | ||
.then(instance => instance.add(testContractAddress)) | ||
.then(assert.fail, assertError)); | ||
|
||
it('add contract', () => | ||
ContractRegistry.deployed() | ||
.then(registry => | ||
registry.setRecorder(accounts[1]) | ||
.then(() => registry.add(testContractAddress, { from: accounts[1] })) | ||
.then(() => registry.getContractsCount.call()) | ||
.then(contractsCount => assert.equal(contractsCount, 1)) | ||
.then(() => registry.contracts.call(0)) | ||
.then(contract => assert.equal(contract, testContractAddress)))); | ||
|
||
it('add contract invokes Added event', () => | ||
ContractRegistry.deployed() | ||
.then((registry) => { | ||
const filter = registry.Added(); | ||
return registry.setRecorder(accounts[0]) | ||
.then(() => registry.add(testContractAddress)) | ||
.then(() => { | ||
const events = filter.get(); | ||
assert.equal(events.length, 1); | ||
assert.equal(events[0].args.contractAddress, testContractAddress); | ||
}); | ||
})); | ||
}); |
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,6 @@ | ||
/* global assert */ | ||
|
||
module.exports = { | ||
assertError: error => | ||
assert.equal(error.message, 'VM Exception while processing transaction: invalid opcode'), | ||
}; |