Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
describe("server/getters/get-user-trading-positions#Binary-1", () => {
let db;
var augur = new Augur();
var universe = "0x000000000000000000000000000000000000000b";
var logFactory = makeLogFactory(universe);
var yesShareToken = "0x0124000000000000000000000000000000000000";
var account = "0x0000000000000000000000000000000000b0b001";
var marketId = "0x0000000000000000000000000000000000000211";
var logs = [
logFactory.OrderFilled({
universe,
shareToken: yesShareToken,
filler: account,
orderId: "0x8000000000000000000000000000000000000000000000000000000000001b0b",
amountFilled: new BigNumber(10).pow(15), // 10 shares
numFillerTokens: ethToWei(bn(3.5)),
numFillerShares: ZERO,
}),
describe("server/getters/get-user-trading-positions#Binary-1", () => {
let db;
var augur = new Augur();
var universe = "0x000000000000000000000000000000000000000b";
var logFactory = makeLogFactory(universe);
var yesShareToken = "0x0124000000000000000000000000000000000000";
var account = "0x0000000000000000000000000000000000b0b001";
var marketId = "0x0000000000000000000000000000000000000211";
var logs = [
logFactory.OrderFilled({
universe,
shareToken: yesShareToken,
filler: account,
orderId: "0x8000000000000000000000000000000000000000000000000000000000001b0b",
amountFilled: new BigNumber(10).pow(15), // 10 shares
numFillerTokens: ethToWei(bn(3.5)),
numFillerShares: ZERO,
}),
const { BigNumber } = require("bignumber.js");
const Augur = require("augur.js");
import { setupTestDb, seedDb } from "../test.database";
import { processOrderCreatedLog } from "src/blockchain/log-processors/order-created";
import { numTicksToTickSize } from "src/utils/convert-fixed-point-to-decimal";
import { checkMarketLiquidityUpdates } from "src/blockchain/check-market-liquidity-updates";
const augur = new Augur();
// function validate(testCase) {
// function assertHas(prop) {
// if (!testCase.hasOwnProperty(prop)) throw new Error(`expected test case to have property ${prop}, testCase=${testCase}`);
// }
// assertHas("name");
// assertHas("marketId");
// assertHas("logs");
// assertHas("expectedSpreadPercentMarket");
// assertHas("expectedSpreadPercentOutcome1"); // every testCase checks outcome 1, but only categoricals check [0, numOutcomes-1]
// return testCase;
// }
// validateROI validates a testCase related to invalidROIPercent
function validateROI(testCase) {
function assertHas(prop) {
const runTest = (t) => {
test(t.description, async () => {
return db.transaction(async (trx) => {
await(await processMarketCreatedLog(t.params.augur, t.params.log))(trx);
t.assertions.onAdded(await getState(trx, t.params.log), false);
await(await processMarketCreatedLogRemoval(t.params.augur, t.params.log))(trx);
t.assertions.onRemoved(await getState(trx, t.params.log));
await(await processMarketCreatedLog(t.params.augur, t.params.log))(trx);
t.assertions.onAdded(await getState(trx, t.params.log), true);
await(await processMarketCreatedLogRemoval(t.params.augur, t.params.log))(trx);
t.assertions.onRemoved(await getState(trx, t.params.log));
});
});
};
const constants = new Augur().constants;
runTest({
description: "yesNo market MarketCreated log and removal",
params: {
log: {
blockNumber: 7,
transactionHash: "0x000000000000000000000000000000000000000000000000000000000000A000",
logIndex: 0,
universe: "0x000000000000000000000000000000000000000b",
market: "0x1111111111111111111111111111111111111111",
marketCreator: "0x0000000000000000000000000000000000000b0b",
marketCreationFee: "0.1",
topic: "TEST_CATEGORY",
marketType: "0",
minPrice: (new BigNumber("0", 10)).toString(),
maxPrice: "1",
description: "this is a test market",
const runTest = (t) => {
test(t.description, async () => {
return db.transaction(async (trx) => {
await(await processMarketCreatedLog(t.params.augur, t.params.log))(trx);
t.assertions.onAdded(await getState(trx, t.params.log), false);
await(await processMarketCreatedLogRemoval(t.params.augur, t.params.log))(trx);
t.assertions.onRemoved(await getState(trx, t.params.log));
await(await processMarketCreatedLog(t.params.augur, t.params.log))(trx);
t.assertions.onAdded(await getState(trx, t.params.log), true);
await(await processMarketCreatedLogRemoval(t.params.augur, t.params.log))(trx);
t.assertions.onRemoved(await getState(trx, t.params.log));
});
});
};
const constants = new Augur().constants;
runTest({
description: "yesNo market MarketCreated log and removal",
params: {
log: {
blockNumber: 7,
transactionHash: "0x000000000000000000000000000000000000000000000000000000000000A000",
logIndex: 0,
universe: "0x000000000000000000000000000000000000000b",
market: "0x1111111111111111111111111111111111111111",
marketCreator: "0x0000000000000000000000000000000000000b0b",
marketCreationFee: "0.1",
topic: "TEST_CATEGORY",
marketType: "0",
minPrice: (new BigNumber("0", 10)).toString(),
maxPrice: "1",
description: "this is a test market",
"use strict";
const assert = require("chai").assert;
const { fix } = require("speedomatic");
const setupTestDb = require("../../test.database");
const { BigNumber } = require("bignumber.js");
const { processOrderCreatedLog, processOrderCreatedLogRemoval } = require("../../../../build/blockchain/log-processors/order-created");
const Augur = require("augur.js");
const augur = new Augur();
describe("blockchain/log-processors/order-created", () => {
const test = (t) => {
const getState = (db, params, callback) => db("orders").where("orderId", params.log.orderId).asCallback(callback);
it(t.description, (done) => {
setupTestDb((err, db) => {
assert.ifError(err);
db.transaction((trx) => {
processOrderCreatedLog(trx, t.params.augur, t.params.log, (err) => {
assert.ifError(err);
getState(trx, t.params, (err, records) => {
t.assertions.onAdded(err, records);
processOrderCreatedLogRemoval(trx, t.params.augur, t.params.log, (err) => {
assert.ifError(err);
getState(trx, t.params, (err, records) => {
t.assertions.onRemoved(err, records);
"use strict";
const assert = require("chai").assert;
const { parallel } = require("async");
const { fix } = require("speedomatic");
const setupTestDb = require("../../../test.database");
const { processOrderFilledLog, processOrderFilledLogRemoval } = require("../../../../build/blockchain/log-processors/order-filled");
const Augur = require("augur.js");
const augur = new Augur();
describe("blockchain/log-processors/order-filled", () => {
const test = (t) => {
const getState = (db, params, aux, callback) => parallel({
orders: next => db("orders").where("orderId", params.log.orderId).asCallback(next),
trades: next => db("trades").where("orderId", params.log.orderId).asCallback(next),
markets: next => db.first("volume", "sharesOutstanding").from("markets").where("marketId", aux.marketId).asCallback(next),
outcomes: next => db.select("price", "volume").from("outcomes").where({ marketId: aux.marketId }).asCallback(next),
categories: next => db.first("popularity").from("categories").where("category", aux.category).asCallback(next),
positions: next => db("positions").where("account", params.log.filler).asCallback(next),
}, callback);
it(t.description, (done) => {
setupTestDb((err, db) => {
assert.isNull(err);
db.transaction((trx) => {
t.params.augur.utils = augur.utils;
return {
position: "2",
realized: "0",
unrealized: "0",
meanOpenPrice: "0.75",
queued: "0",
};
},
getPositionInMarket: (p, callback) => {
expect(p.market).toBe("0x0000000000000000000000000000000000000001");
expect(["0x0000000000000000000000000000000000000b0b", "FILLER_ADDRESS"].indexOf(p.address)).toBeGreaterThan(-1);
callback(null, ["2", "0", "0", "0", "0", "0", "0", "0"]);
},
normalizePrice: p => p.price,
},
utils: new Augur().utils,
};
describe("blockchain/log-processors/order-filled", () => {
let db;
beforeEach(async () => {
db = await setupTestDb();
});
test("OrderFilled full log and removal", async () => {
const log = {
shareToken: "0x0100000000000000000000000000000000000000",
filler: "FILLER_ADDRESS",
orderId: "0x1000000000000000000000000000000000000000000000000000000000000000",
amountFilled: "100000000000000",
numCreatorShares: "0",
numCreatorTokens: fix("1", "string"),
params: {
log: {
universe: "0x000000000000000000000000000000000000000b",
market: "0x0000000000000000000000000000000000000001",
stakeToken: "0x1000000000000000000000000000000000000000",
reporter: "0x0000000000000000000000000000000000000b0b",
isDesignatedReporter: true,
payoutNumerators: [0, 1],
invalid: false,
blockNumber: 1500001,
amountStaked: "2829",
transactionHash: "0x0000000000000000000000000000000000000000000000000000000000000B00",
logIndex: 0,
},
augur: {
constants: new Augur().constants,
api: {
Market: {
getInitialReporter: (p, callback) => {
callback(null, "0x0000000000000000000000000000000000abe123");
},
},
},
rpc: {
eth: {
getBalance: (p, callback) => {
assert.deepEqual(p, ["0xbbb0000000000000000000000000000000000001", "latest"]);
callback(null, "0x22");
},
},
},
},
describe("server/getters/get-user-trading-positions frozenFundsTotal ignores validityBondSize from finalized market", () => {
let db;
var augur = new Augur();
var universe = "0x000000000000000000000000000000000000000b";
var logFactory = makeLogFactory(universe);
var account = "0x0000000000000000000000000000000000b0b001";
var marketId = "0x000000000000000000000000000000000000021c";
beforeEach(async () => {
processBlock.getCurrentTime.mockReturnValue(Date.now()/1000);
db = await setupTestDb(augur, [], logFactory.getBlockDetails(), true);
});
afterEach(async () => {
await db.destroy();
});
const getUserTradingPositions = async (params) => {
return JSON.parse(JSON.stringify(await dispatchJsonRpcRequest(db, { method: "getUserTradingPositions", params }, augur)));