const MarketContractMPX = artifacts.require('MarketContractMPX');
const CollateralToken = artifacts.require('CollateralToken');
const MathLib = artifacts.require('MathLib');

contract('MarketContractMPX', function(accounts) {
  const expiration = new Date().getTime() / 1000 + 60 * 50; // order expires 50 minutes from now.
  const oracleURL = 'api.coincap.io/v2/rates/bitcoin';
  const oracleStatistic = 'rateUsd';
  let marketContract;

  before(async function() {
    marketContract = await MarketContractMPX.new(
      'NTC,LBTC,SBTC',
      [accounts[0], CollateralToken.address],
      accounts[0], // substitute our address for the oracleHubAddress so we can callback from queries.
      [0, 150, 2, 2, 0, 0, expiration],
      oracleURL,
      oracleStatistic
    );
  });

  it('Constructor sets needed variables correctly', async function() {
    assert.equal(await marketContract.ORACLE_URL(), oracleURL);
    assert.equal(await marketContract.ORACLE_STATISTIC(), oracleStatistic);
    assert.equal(await marketContract.ORACLE_HUB_ADDRESS(), accounts[0]);
  });

  it('oracleCallBack can only be called by the oracleHub', async function() {
    let error = null;
    try {
      await marketContract.oracleCallBack(100, { from: accounts[1] });
    } catch (err) {
      error = err;
    }
    assert.ok(
      error instanceof Error,
      'should not be able to be called from an address that is an oracleHub'
    );

    const txHash = await marketContract.oracleCallBack(100, { from: accounts[0] });
    assert.notEqual(txHash, null, 'oracleCallBack from oracle hub address failed');
  });

  it('oracleCallBack can push contract into settlement', async function() {
    assert.isTrue(!(await marketContract.isSettled()), 'marketContract is already settled');
    await marketContract.oracleCallBack(175, { from: accounts[0] }); // price above cap!
    assert.isTrue(await marketContract.isSettled(), 'marketContract is not settled');
  });

  it('oracleCallBack can not be called after settlement', async function() {
    assert.isTrue(await marketContract.isSettled(), 'marketContract is not settled');
    let error = null;
    try {
      await marketContract.oracleCallBack(175, { from: accounts[0] }); // price above cap!
    } catch (err) {
      error = err;
    }
    assert.ok(error instanceof Error, 'should not be able to be called after expiration');
  });
});

@@ -594,17 +594,17 @@
 ccounts%5B
-0
+8
 %5D, // su
@@ -1055,17 +1055,17 @@
 ccounts%5B
-0
+8
 %5D);%0A  %7D)
@@ -1496,25 +1496,25 @@
 m: accounts%5B
-0
+8
 %5D %7D);%0A    as
@@ -1821,33 +1821,33 @@
  from: accounts%5B
-0
+8
 %5D %7D); // price a
@@ -2208,17 +2208,17 @@
 ccounts%5B
-0
+8
 %5D %7D); //
@@ -2376,13 +2376,1230 @@
 );%0A  %7D);
+%0A%0A  it('arbitrateSettlement can only be called by the oracleHub', async function() %7B%0A    let error = null;%0A    try %7B%0A      await marketContract.arbitrateSettlement(100, %7B from: accounts%5B8%5D %7D);%0A    %7D catch (err) %7B%0A      error = err;%0A    %7D%0A    assert.ok(%0A      error instanceof Error,%0A      'should not be able to be called from an address that is not the owner'%0A    );%0A%0A    const txHash = await marketContract.arbitrateSettlement(100, %7B from: accounts%5B0%5D %7D);%0A    assert.notEqual(txHash, null, 'arbitrateSettlement from owner address failed');%0A  %7D);%0A%0A  it('arbitrateSettlement can push contract into settlement', async function() %7B%0A    marketContract = await MarketContractMPX.new(%0A      'NTC,LBTC,SBTC',%0A      %5Baccounts%5B0%5D, CollateralToken.address%5D,%0A      accounts%5B8%5D, // substitute our address for the oracleHubAddress so we can callback from queries.%0A      %5B25, 150, 2, 2, 0, 0, expiration%5D,%0A      oracleURL,%0A      oracleStatistic%0A    );%0A%0A    assert.isTrue(!(await marketContract.isSettled()), 'marketContract is already settled');%0A    await marketContract.arbitrateSettlement(5, %7B from: accounts%5B0%5D %7D); // price below floor%0A    assert.isTrue(await marketContract.isSettled(), 'marketContract is not settled');%0A  %7D);
 %0A%7D);%0A

add test for arbitrate settlement