Skip to content

Commit

Permalink
Add to Exchange features imported from DexTrade (#20)
Browse files Browse the repository at this point in the history
* Add code from abandoned Trade smart contract

* Add initial unit test
  • Loading branch information
jijordre committed Apr 23, 2018
1 parent 8bcb9a7 commit cf80112
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 8 deletions.
33 changes: 31 additions & 2 deletions contracts/Exchange.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,43 @@ pragma solidity ^0.4.21;
/**
@title Exchange
@notice The orchestrator of trades and payments on-chain.
@dev The essence and trade specific parts of the previous Trade smart contract.
*/
contract Exchange {

//
// Structures
// -----------------------------------------------------------------------------------------------------------------
struct Signature {
bytes32 r;
bytes32 s;
uint8 v;
}

struct Trade {
uint256 buyOrderHash;
uint256 sellOrderHash;
uint256 buyerOrderNonce; // These ones should be obtained from orders map (accessed by hash),
uint256 sellerOrderNonce; // but we don't have such information.
address buyer;
address seller;
uint256 tokenAmount;
uint256 etherAmount;
address token;
bool immediateSettlement;
Signature signature;
}

struct Settlement {
// uint256[] tradeNonces;
// uint256[] tradeHashes;
// // Balances here
// uint256[] signature;
}

//
// Variables
// -----------------------------------------------------------------------------------------------------------------
address private owner;
address public owner;

//
// Events
Expand Down
58 changes: 52 additions & 6 deletions test/scenarios/Exchange.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,53 @@
module.exports = function (glob) {
describe("Exchange", function () {
it("T001: TO-DO", function (done) {
done();
});
});
const chai = require('chai');
const chaiAsPromised = require("chai-as-promised");
const Exchange = artifacts.require('Exchange');

chai.use(chaiAsPromised);
chai.should();

module.exports = (glob) => {
describe('Exchange', () => {

let instance = null;

before(async () => {
instance = await Exchange.deployed();
});

describe('constructor', () => {
it('should initialize fields', async () => {
const owner = await instance.owner.call();
owner.should.equal(glob.owner);
});
});

describe('owner()', () => {
it('should equal value initialized at construction time', async () => {
const owner = await instance.owner.call();
owner.should.equal(glob.owner);
});
});

describe('changeOwner()', () => {
describe('if called with current owner as sender', () => {
after(async () => {
await instance.changeOwner(glob.owner, {from: glob.user_a});
});

it('should successfully set new owner and emit event', async () => {
const result = await instance.changeOwner(glob.user_a);
result.logs.should.be.an('array').and.have.lengthOf(1);
result.logs[0].event.should.equal('OwnerChangedEvent');
const owner = await instance.owner.call();
owner.should.equal(glob.user_a);
});
});

describe('if called with sender that is not current owner', () => {
it('should fail to set new owner', async () => {
instance.changeOwner(glob.user_a, {from: glob.user_a}).should.be.rejected;
});
});
});
});
};

0 comments on commit cf80112

Please sign in to comment.