This repository has been archived by the owner on Jan 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from MoMannn/dev
ChainableXcert
- Loading branch information
Showing
8 changed files
with
177 additions
and
12 deletions.
There are no files selected for viewing
File renamed without changes.
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
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,68 @@ | ||
pragma solidity ^0.4.19; | ||
|
||
import "./Xcert.sol"; | ||
|
||
contract ChainableXcert is Xcert { | ||
|
||
/* | ||
* @dev This emits when additional proof is chained. | ||
*/ | ||
event ChainedProof(uint256 indexed tokenId, string proof, uint256 index); | ||
|
||
function ChainableXcert(string _name, | ||
string _symbol) | ||
Xcert(_name, _symbol) | ||
public | ||
{ | ||
supportedInterfaces[0xc1dcb551] = true; // ChainableXcert | ||
} | ||
|
||
/* | ||
* @dev Adds new proof to chain of proofs for token. | ||
* @param _tokenId Id of Xcert that we want to add proof to. | ||
* @param _proof New proof we want to add to NFToken. | ||
*/ | ||
function chain(uint256 _tokenId, | ||
string _proof) | ||
validNFToken(_tokenId) | ||
onlyOwner | ||
external | ||
{ | ||
|
||
require(bytes(_proof).length > 0); | ||
|
||
idToProof[_tokenId].push(_proof); | ||
|
||
ChainedProof(_tokenId, _proof, idToProof[_tokenId].length.sub(1)); | ||
} | ||
|
||
/* | ||
* @dev Gets proof by index. | ||
* @param _tokenId Id of the Xcert we want to get proof of. | ||
* @param _index Index of the proof we want to get. | ||
*/ | ||
function getProofByIndex(uint256 _tokenId, | ||
uint256 _index) | ||
validNFToken(_tokenId) | ||
external | ||
view | ||
returns (string) | ||
{ | ||
require(_index < idToProof[_tokenId].length); | ||
return idToProof[_tokenId][_index]; | ||
} | ||
|
||
/* | ||
* @dev Gets the count of all proofs for a Xcert. | ||
* @param _tokenId Id of the Xcert we want to get proof of. | ||
*/ | ||
function getProofCount(uint256 _tokenId) | ||
validNFToken(_tokenId) | ||
external | ||
view | ||
returns (uint256) | ||
{ | ||
return idToProof[_tokenId].length; | ||
} | ||
|
||
} |
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
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
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,44 @@ | ||
const ChainableXcert = artifacts.require('ChainableXcert'); | ||
const util = require('ethjs-util'); | ||
const assertRevert = require('../helpers/assertRevert'); | ||
|
||
contract('ChainableXcert', (accounts) => { | ||
let xcert; | ||
let id1 = web3.sha3('test1'); | ||
let mockProof = "1e205550c271490347e5e2393a02e94d284bbe9903f023ba098355b8d75974c8"; | ||
let mockProof2 = "1e205550c271490347e5e2393a02e94d284bbe9903f023ba098355b8d75974d5"; | ||
|
||
beforeEach(async function () { | ||
xcert = await ChainableXcert.new('Foo', 'F'); | ||
await xcert.mint(accounts[0], id1, mockProof, 'url1'); | ||
}); | ||
|
||
it('correctly chains additional proof', async () => { | ||
await xcert.chain(id1, mockProof2); | ||
var proof = await xcert.getProof(id1); | ||
assert.equal(proof, mockProof2); | ||
}); | ||
|
||
it('reverts trying to chain empty proof', async () => { | ||
await assertRevert(xcert.chain(id1, "")); | ||
}); | ||
|
||
it('correctly gets proof by index', async () => { | ||
await xcert.chain(id1, mockProof2); | ||
var proof = await xcert.getProofByIndex(id1, 1); | ||
assert.equal(proof, mockProof2); | ||
}); | ||
|
||
it('reverts trying to get proof for none existant index', async () => { | ||
await assertRevert(xcert.getProofByIndex(id1, 1)); | ||
}); | ||
|
||
it('returns correct proof count', async () => { | ||
var proofCount = await xcert.getProofCount(id1); | ||
assert.equal(proofCount, 1); | ||
|
||
await xcert.chain(id1, mockProof2); | ||
proofCount = await xcert.getProofCount(id1); | ||
assert.equal(proofCount, 2); | ||
}); | ||
}); |
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
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,43 @@ | ||
const Xcert = artifacts.require('Xcert'); | ||
const BurnableXcert = artifacts.require('BurnableXcert'); | ||
const ChainableXcert = artifacts.require('ChainableXcert'); | ||
const SettableTransferXcert = artifacts.require('SettableTransferXcert'); | ||
const Selector = artifacts.require('Selector'); | ||
|
||
contract('Selector', (accounts) => { | ||
|
||
let selector; | ||
|
||
beforeEach(async function () { | ||
selector = await Selector.new(); | ||
}); | ||
|
||
it('Checks Xcert selector', async () => { | ||
var xcert = await Xcert.new('Foo', 'F'); | ||
var bytes = await selector.calculateXcertSelector(); | ||
var supports = await xcert.supportsInterface(bytes); | ||
assert.equal(supports, true); | ||
}); | ||
|
||
it('Checks BurnableXcert selector', async () => { | ||
var xcert = await BurnableXcert.new('Foo', 'F'); | ||
var bytes = await selector.calculateBurnableXcertSelector(); | ||
var supports = await xcert.supportsInterface(bytes); | ||
assert.equal(supports, true); | ||
}); | ||
|
||
it('Checks SettableTransferXcert selector', async () => { | ||
var xcert = await SettableTransferXcert.new('Foo', 'F'); | ||
var bytes = await selector.calculateSettableTransferXcertSelector(); | ||
var supports = await xcert.supportsInterface(bytes); | ||
assert.equal(supports, true); | ||
}); | ||
|
||
it('Checks ChainableXcert selector', async () => { | ||
var xcert = await ChainableXcert.new('Foo', 'F'); | ||
var bytes = await selector.calculateChainableXcertSelector(); | ||
var supports = await xcert.supportsInterface(bytes); | ||
assert.equal(supports, true); | ||
}); | ||
|
||
}); |