1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

next iteration

This commit is contained in:
Sebastian Gerske 2018-10-18 09:19:10 +02:00
parent 5719a667ea
commit 1b8aa52c40
12 changed files with 117 additions and 25 deletions

View File

@ -25,12 +25,12 @@ export default class ContractHandler {
const deployerAddress = (await web3.eth.getAccounts())[0] const deployerAddress = (await web3.eth.getAccounts())[0]
// deploy libs // deploy libs
const dll = await ContractHandler.deployContract(web3, "DLL", deployerAddress) const dll = await ContractHandler.deployContract("DLL", deployerAddress)
const attributeStore = await ContractHandler.deployContract(web3, "AttributeStore", deployerAddress) const attributeStore = await ContractHandler.deployContract("AttributeStore", deployerAddress)
// deploy contracts // deploy contracts
const token = await ContractHandler.deployContract(web3, "OceanToken", deployerAddress) const token = await ContractHandler.deployContract("OceanToken", deployerAddress)
const plcrVoting = await ContractHandler.deployContract(web3, "PLCRVoting", deployerAddress, { const plcrVoting = await ContractHandler.deployContract("PLCRVoting", deployerAddress, {
args: [token.options.address], args: [token.options.address],
tokens: [ tokens: [
{ {
@ -40,16 +40,16 @@ export default class ContractHandler {
}, },
], ],
}) })
const registry = await ContractHandler.deployContract(web3, "OceanRegistry", deployerAddress, { const registry = await ContractHandler.deployContract("OceanRegistry", deployerAddress, {
args: [token.options.address, plcrVoting.options.address], args: [token.options.address, plcrVoting.options.address],
}) })
const market = await ContractHandler.deployContract(web3, "OceanMarket", deployerAddress, { const market = await ContractHandler.deployContract("OceanMarket", deployerAddress, {
args: [token.options.address, registry.options.address], args: [token.options.address, registry.options.address],
}) })
const dispute = await ContractHandler.deployContract(web3, "OceanDispute", deployerAddress, { const dispute = await ContractHandler.deployContract("OceanDispute", deployerAddress, {
args: [market.options.address, registry.options.address, plcrVoting.options.address], args: [market.options.address, registry.options.address, plcrVoting.options.address],
}) })
await ContractHandler.deployContract(web3, "OceanAuth", deployerAddress, { await ContractHandler.deployContract("OceanAuth", deployerAddress, {
args: [market.options.address, dispute.options.address], args: [market.options.address, dispute.options.address],
}) })
} }
@ -84,13 +84,15 @@ export default class ContractHandler {
return bytecode.toString() return bytecode.toString()
} }
private static async deployContract(web3, name, from, params?): Promise<Contract> { private static async deployContract(name: string, from: string, params?): Promise<Contract> {
// dont redeploy if there is already something loaded // dont redeploy if there is already something loaded
if (contracts.has(name)) { if (contracts.has(name)) {
return contracts.get(name) return contracts.get(name)
} }
const web3 = Web3Provider.getWeb3()
let contractInstance: Contract let contractInstance: Contract
try { try {
Logger.log("Deploying", name) Logger.log("Deploying", name)

View File

@ -1,4 +1,4 @@
import * as assert from "assert" import {assert} from "chai"
import ConfigProvider from "../../src/ConfigProvider" import ConfigProvider from "../../src/ConfigProvider"
import ContractHandler from "../../src/keeper/ContractHandler" import ContractHandler from "../../src/keeper/ContractHandler"
import config from "../config" import config from "../config"
@ -13,8 +13,16 @@ describe("ContractHandler", () => {
describe("#get()", () => { describe("#get()", () => {
it("should load and get OceanToken correctly", async () => { it("should load and get OceanToken correctly", async () => {
assert(await ContractHandler.get("OceanToken") !== null) assert(await ContractHandler.get("OceanToken"))
}) })
it("should fail to load an unknown contract", (done) => {
ContractHandler.get("OceanXXX")
.catch(() => {
done()
})
})
}) })
}) })

View File

@ -0,0 +1,68 @@
import ConfigProvider from "../../src/ConfigProvider"
import ContractHandler from "../../src/keeper/ContractHandler"
import config from "../config"
import ContractWrapperBaseMock from "../mocks/ContractWrapperBase.Mock"
const wrappedContract = new ContractWrapperBaseMock("OceanToken")
before(async () => {
ConfigProvider.configure(config)
await ContractHandler.deployContracts()
wrappedContract.initMock()
})
describe("ContractWrapperBase", () => {
describe("#call()", () => {
it("should fail to call on an unknown contract function", (done) => {
wrappedContract.callMock("balanceOfxxx", [])
.catch(() => {
done()
})
})
it("should fail to call on an contract function with wrong set of parameters", (done) => {
wrappedContract.callMock("balanceOf", [])
.catch(() => {
done()
})
})
it("should fail to call on an unknown contract function", (done) => {
wrappedContract.sendMock("balanceOfxxx", "0x00", ["0x00"])
.catch(() => {
done()
})
})
it("should fail to call on an contract function with wrong set of parameters", (done) => {
wrappedContract.sendMock("approve", "0x000", [])
.catch(() => {
done()
})
})
})
describe("#getEventData()", () => {
it("should fail on unknown event", (done) => {
wrappedContract.getEventData("crazyevent", {})
.catch(() => {
done()
})
})
})
})

View File

@ -1,4 +1,4 @@
import * as assert from "assert" import {assert} from "chai"
import ConfigProvider from "../../src/ConfigProvider" import ConfigProvider from "../../src/ConfigProvider"
import ContractHandler from "../../src/keeper/ContractHandler" import ContractHandler from "../../src/keeper/ContractHandler"
import Keeper from "../../src/keeper/Keeper" import Keeper from "../../src/keeper/Keeper"

View File

@ -0,0 +1,15 @@
import ContractWrapperBase from "../../src/keeper/ContractWrapperBase"
export default class ContractWrapperBaseMock extends ContractWrapperBase {
public async initMock() {
this.init()
}
public async callMock(name: string, args: any[], from?: string) {
return this.call(name, args, from)
}
public async sendMock(name: string, from: string, args: any[]) {
return this.sendTransaction(name, from, args)
}
}

View File

@ -1,5 +1,4 @@
import OceanBase from "../../src/ocean/OceanBase" import OceanBase from "../../src/ocean/OceanBase"
export default class OceanBaseMock extends OceanBase { export default class OceanBaseMock extends OceanBase {
} }

View File

@ -1,6 +1,6 @@
import Provider from "../src/provider/Provider" import Provider from "../../src/provider/Provider"
export default class MockProvider extends Provider { export default class ProviderMock extends Provider {
public static async getAccessUrl(accessToken: any, payload: any): Promise<string> { public static async getAccessUrl(accessToken: any, payload: any): Promise<string> {
return "http://test/test" return "http://test/test"

View File

@ -1,4 +1,4 @@
import * as assert from "assert" import {assert} from "chai"
import ConfigProvider from "../../src/ConfigProvider" import ConfigProvider from "../../src/ConfigProvider"
import ContractHandler from "../../src/keeper/ContractHandler" import ContractHandler from "../../src/keeper/ContractHandler"
import Web3Provider from "../../src/keeper/Web3Provider" import Web3Provider from "../../src/keeper/Web3Provider"

View File

@ -1,4 +1,4 @@
import * as assert from "assert" import {assert} from "chai"
import ConfigProvider from "../../src/ConfigProvider" import ConfigProvider from "../../src/ConfigProvider"
import ContractHandler from "../../src/keeper/ContractHandler" import ContractHandler from "../../src/keeper/ContractHandler"
import Account from "../../src/ocean/Account" import Account from "../../src/ocean/Account"
@ -7,7 +7,7 @@ import Ocean from "../../src/ocean/Ocean"
import Order from "../../src/ocean/Order" import Order from "../../src/ocean/Order"
import ProviderProvider from "../../src/provider/ProviderProvider" import ProviderProvider from "../../src/provider/ProviderProvider"
import config from "../config" import config from "../config"
import MockProvider from "../MockProvider" import ProviderMock from "../mocks/Provider.Mock"
const testName = "Test Asset 2" const testName = "Test Asset 2"
const testDescription = "This asset is pure owange" const testDescription = "This asset is pure owange"
@ -22,7 +22,7 @@ let testPublisher: Account
before(async () => { before(async () => {
ConfigProvider.configure(config) ConfigProvider.configure(config)
ProviderProvider.setProvider(MockProvider) ProviderProvider.setProvider(ProviderMock)
await ContractHandler.deployContracts() await ContractHandler.deployContracts()
ocean = await Ocean.getInstance(config) ocean = await Ocean.getInstance(config)

View File

@ -1,4 +1,4 @@
import * as assert from "assert" import {assert} from "chai"
import ConfigProvider from "../../src/ConfigProvider" import ConfigProvider from "../../src/ConfigProvider"
import ContractHandler from "../../src/keeper/ContractHandler" import ContractHandler from "../../src/keeper/ContractHandler"
import Account from "../../src/ocean/Account" import Account from "../../src/ocean/Account"

View File

@ -1,5 +1,5 @@
import * as assert from "assert" import {assert} from "chai"
import OceanBase from "./OceanBaseMock" import OceanBaseMock from "../mocks/OceanBase.Mock"
describe("OceanBase", () => { describe("OceanBase", () => {
@ -8,7 +8,7 @@ describe("OceanBase", () => {
it("should get the id", async () => { it("should get the id", async () => {
const id = "test" const id = "test"
const oceanBase = new OceanBase(id) const oceanBase = new OceanBaseMock(id)
assert(oceanBase.getId() === id) assert(oceanBase.getId() === id)
}) })
@ -20,7 +20,7 @@ describe("OceanBase", () => {
it("should get the id", async () => { it("should get the id", async () => {
const id = "test" const id = "test"
const oceanBase = new OceanBase() const oceanBase = new OceanBaseMock()
oceanBase.setId(id) oceanBase.setId(id)
assert(oceanBase.getId() === id) assert(oceanBase.getId() === id)

View File

@ -1,4 +1,4 @@
import * as assert from "assert" import {assert} from "chai"
import ConfigProvider from "../../src/ConfigProvider" import ConfigProvider from "../../src/ConfigProvider"
import ContractHandler from "../../src/keeper/ContractHandler" import ContractHandler from "../../src/keeper/ContractHandler"
import AccessStatus from "../../src/models/AccessStatus" import AccessStatus from "../../src/models/AccessStatus"