Skip to content
This repository has been archived by the owner on Jan 12, 2019. It is now read-only.

Commit

Permalink
Rename of SettableTransferXcert to PausableXcert.
Browse files Browse the repository at this point in the history
  • Loading branch information
MoMannn committed Apr 12, 2018
1 parent 4f4b210 commit afe930d
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 127 deletions.
6 changes: 3 additions & 3 deletions contracts/mocks/XcertMock.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
pragma solidity ^0.4.19;

import "../../contracts/tokens/BurnableXcert.sol";
import "../../contracts/tokens/SettableTransferXcert.sol";
import "../../contracts/tokens/PausableXcert.sol";
import "../../contracts/tokens/ChainableXcert.sol";

contract XcertMock is BurnableXcert, SettableTransferXcert, ChainableXcert {
contract XcertMock is BurnableXcert, PausableXcert, ChainableXcert {

function XcertMock(string _name, string _symbol)
BurnableXcert(_name, _symbol)
SettableTransferXcert(_name, _symbol)
PausableXcert(_name, _symbol)
ChainableXcert(_name, _symbol)
public
{
Expand Down
53 changes: 53 additions & 0 deletions contracts/tokens/PausableXcert.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
pragma solidity ^0.4.19;

import "./Xcert.sol";

contract PausableXcert is Xcert {

/*
* @dev This emits when ability of beeing able to transfer NFTokens changes (paused/unpaused).
*/
event IsPaused(bool _isPaused);

/*
* @dev Are NFTokens paused or not.
*/
bool public isPaused;

function PausableXcert(string _name, string _symbol)
Xcert(_name, _symbol)
public
{
supportedInterfaces[0xbedb86fb] = true; // PausableXcert
isPaused = false;
}

/*
* @dev Guarantees that the msg.sender is allowed to transfer NFToken.
* @param _tokenId ID of the NFToken to transfer.
*/
modifier canTransfer(uint256 _tokenId) {
address owner = idToOwner[_tokenId];
require(!isPaused && (
owner == msg.sender
|| getApproved(_tokenId) == msg.sender
|| ownerToOperators[owner][msg.sender])
);

_;
}

/*
* @dev Sets if NFTokens are paused or not.
* @param _isPaused Pause status.
*/
function setPause(bool _isPaused)
external
onlyOwner
{
require(isPaused != _isPaused);
isPaused = _isPaused;
IsPaused(_isPaused);
}

}
53 changes: 0 additions & 53 deletions contracts/tokens/SettableTransferXcert.sol

This file was deleted.

8 changes: 4 additions & 4 deletions contracts/utils/Selector.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pragma solidity ^0.4.19;

import "../tokens/Xcert.sol";
import "../tokens/BurnableXcert.sol";
import "../tokens/SettableTransferXcert.sol";
import "../tokens/PausableXcert.sol";
import "../tokens/ChainableXcert.sol";
import "../protocol/Minter.sol";
import "../protocol/Trader.sol";
Expand All @@ -23,9 +23,9 @@ contract Selector {
return i.burn.selector;
}

function calculateSettableTransferXcertSelector() public pure returns (bytes4) {
SettableTransferXcert i;
return i.setTransferable.selector;
function calculatePausableXcertSelector() public pure returns (bytes4) {
PausableXcert i;
return i.setPause.selector;
}

function calculateChainableXcertSelector() public pure returns (bytes4) {
Expand Down
17 changes: 0 additions & 17 deletions test/mocks/XcertMock.sol

This file was deleted.

45 changes: 45 additions & 0 deletions test/tokens/PausableXcert.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const PausableXcert = artifacts.require('PausableXcert');
const util = require('ethjs-util');
const assertRevert = require('../helpers/assertRevert');

contract('PausableXcert', (accounts) => {
let xcert;
let id1 = web3.sha3('test1');
let id2 = web3.sha3('test2');
let id3 = web3.sha3('test3');
let id4 = web3.sha3('test4');
let mockProof = "1e205550c271490347e5e2393a02e94d284bbe9903f023ba098355b8d75974c8";

beforeEach(async function () {
xcert = await PausableXcert.new('Foo', 'F');
});

it('correctly sets pause state', async () => {
var { logs } = await xcert.setPause(true);
let isPausedEvent = logs.find(e => e.event === 'IsPaused');
assert.notEqual(isPausedEvent, undefined);
var pauseState = await xcert.isPaused();
assert.equal(pauseState, true);
});

it('reverts trying to set the same pause state', async () => {
await assertRevert(xcert.setPause(false));
});

it('reverts when someone else then the owner tries to change pause state', async () => {
await assertRevert(xcert.setPause(true, {from: accounts[1]}));
});

it('succefully transfers when token is not paused', async () => {
await xcert.mint(accounts[0], id1, mockProof, 'url1');
await xcert.transferFrom(accounts[0], accounts[1], id1);
var owner = await xcert.ownerOf(id1);
assert.equal(owner, accounts[1]);
});

it('reverts trying to transfer when token is paused', async () => {
await xcert.mint(accounts[0], id1, mockProof, 'url1');
await xcert.setPause(true);
await assertRevert(xcert.transferFrom(accounts[0], accounts[1], id1));
});
});
45 changes: 0 additions & 45 deletions test/tokens/SettableTransferXcert.test.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/tokens/XcertMock.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract('XcertMock', (accounts) => {
});

it('reverts trying to transfer when transfers are disabled', async () => {
await xcert.setTransferable(false);
await xcert.setPause(true);
await assertRevert(xcert.transferFrom(accounts[0], accounts[1], id1));
});

Expand Down
8 changes: 4 additions & 4 deletions test/utils/Selector.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const Xcert = artifacts.require('Xcert');
const BurnableXcert = artifacts.require('BurnableXcert');
const ChainableXcert = artifacts.require('ChainableXcert');
const SettableTransferXcert = artifacts.require('SettableTransferXcert');
const PausableXcert = artifacts.require('PausableXcert');
const Minter = artifacts.require('Minter');
const Trader = artifacts.require('Trader');
const Swapper = artifacts.require('Swapper');
Expand Down Expand Up @@ -29,9 +29,9 @@ contract('Selector', (accounts) => {
assert.equal(supports, true);
});

it('Checks SettableTransferXcert selector', async () => {
var xcert = await SettableTransferXcert.new('Foo', 'F');
var bytes = await selector.calculateSettableTransferXcertSelector();
it('Checks PausableXcert selector', async () => {
var xcert = await PausableXcert.new('Foo', 'F');
var bytes = await selector.calculatePausableXcertSelector();
var supports = await xcert.supportsInterface(bytes);
assert.equal(supports, true);
});
Expand Down

0 comments on commit afe930d

Please sign in to comment.