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:
parent
5719a667ea
commit
1b8aa52c40
@ -25,12 +25,12 @@ export default class ContractHandler {
|
||||
const deployerAddress = (await web3.eth.getAccounts())[0]
|
||||
|
||||
// deploy libs
|
||||
const dll = await ContractHandler.deployContract(web3, "DLL", deployerAddress)
|
||||
const attributeStore = await ContractHandler.deployContract(web3, "AttributeStore", deployerAddress)
|
||||
const dll = await ContractHandler.deployContract("DLL", deployerAddress)
|
||||
const attributeStore = await ContractHandler.deployContract("AttributeStore", deployerAddress)
|
||||
|
||||
// deploy contracts
|
||||
const token = await ContractHandler.deployContract(web3, "OceanToken", deployerAddress)
|
||||
const plcrVoting = await ContractHandler.deployContract(web3, "PLCRVoting", deployerAddress, {
|
||||
const token = await ContractHandler.deployContract("OceanToken", deployerAddress)
|
||||
const plcrVoting = await ContractHandler.deployContract("PLCRVoting", deployerAddress, {
|
||||
args: [token.options.address],
|
||||
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],
|
||||
})
|
||||
const market = await ContractHandler.deployContract(web3, "OceanMarket", deployerAddress, {
|
||||
const market = await ContractHandler.deployContract("OceanMarket", deployerAddress, {
|
||||
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],
|
||||
})
|
||||
await ContractHandler.deployContract(web3, "OceanAuth", deployerAddress, {
|
||||
await ContractHandler.deployContract("OceanAuth", deployerAddress, {
|
||||
args: [market.options.address, dispute.options.address],
|
||||
})
|
||||
}
|
||||
@ -84,13 +84,15 @@ export default class ContractHandler {
|
||||
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
|
||||
if (contracts.has(name)) {
|
||||
return contracts.get(name)
|
||||
}
|
||||
|
||||
const web3 = Web3Provider.getWeb3()
|
||||
|
||||
let contractInstance: Contract
|
||||
try {
|
||||
Logger.log("Deploying", name)
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as assert from "assert"
|
||||
import {assert} from "chai"
|
||||
import ConfigProvider from "../../src/ConfigProvider"
|
||||
import ContractHandler from "../../src/keeper/ContractHandler"
|
||||
import config from "../config"
|
||||
@ -13,8 +13,16 @@ describe("ContractHandler", () => {
|
||||
describe("#get()", () => {
|
||||
|
||||
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()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
68
test/keeper/ContractWrapperBase.test.ts
Normal file
68
test/keeper/ContractWrapperBase.test.ts
Normal 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()
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
})
|
@ -1,4 +1,4 @@
|
||||
import * as assert from "assert"
|
||||
import {assert} from "chai"
|
||||
import ConfigProvider from "../../src/ConfigProvider"
|
||||
import ContractHandler from "../../src/keeper/ContractHandler"
|
||||
import Keeper from "../../src/keeper/Keeper"
|
||||
|
15
test/mocks/ContractWrapperBase.Mock.ts
Normal file
15
test/mocks/ContractWrapperBase.Mock.ts
Normal 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)
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
import OceanBase from "../../src/ocean/OceanBase"
|
||||
|
||||
export default class OceanBaseMock extends OceanBase {
|
||||
|
||||
}
|
@ -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> {
|
||||
return "http://test/test"
|
@ -1,4 +1,4 @@
|
||||
import * as assert from "assert"
|
||||
import {assert} from "chai"
|
||||
import ConfigProvider from "../../src/ConfigProvider"
|
||||
import ContractHandler from "../../src/keeper/ContractHandler"
|
||||
import Web3Provider from "../../src/keeper/Web3Provider"
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as assert from "assert"
|
||||
import {assert} from "chai"
|
||||
import ConfigProvider from "../../src/ConfigProvider"
|
||||
import ContractHandler from "../../src/keeper/ContractHandler"
|
||||
import Account from "../../src/ocean/Account"
|
||||
@ -7,7 +7,7 @@ import Ocean from "../../src/ocean/Ocean"
|
||||
import Order from "../../src/ocean/Order"
|
||||
import ProviderProvider from "../../src/provider/ProviderProvider"
|
||||
import config from "../config"
|
||||
import MockProvider from "../MockProvider"
|
||||
import ProviderMock from "../mocks/Provider.Mock"
|
||||
|
||||
const testName = "Test Asset 2"
|
||||
const testDescription = "This asset is pure owange"
|
||||
@ -22,7 +22,7 @@ let testPublisher: Account
|
||||
|
||||
before(async () => {
|
||||
ConfigProvider.configure(config)
|
||||
ProviderProvider.setProvider(MockProvider)
|
||||
ProviderProvider.setProvider(ProviderMock)
|
||||
|
||||
await ContractHandler.deployContracts()
|
||||
ocean = await Ocean.getInstance(config)
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as assert from "assert"
|
||||
import {assert} from "chai"
|
||||
import ConfigProvider from "../../src/ConfigProvider"
|
||||
import ContractHandler from "../../src/keeper/ContractHandler"
|
||||
import Account from "../../src/ocean/Account"
|
||||
|
@ -1,5 +1,5 @@
|
||||
import * as assert from "assert"
|
||||
import OceanBase from "./OceanBaseMock"
|
||||
import {assert} from "chai"
|
||||
import OceanBaseMock from "../mocks/OceanBase.Mock"
|
||||
|
||||
describe("OceanBase", () => {
|
||||
|
||||
@ -8,7 +8,7 @@ describe("OceanBase", () => {
|
||||
it("should get the id", async () => {
|
||||
|
||||
const id = "test"
|
||||
const oceanBase = new OceanBase(id)
|
||||
const oceanBase = new OceanBaseMock(id)
|
||||
|
||||
assert(oceanBase.getId() === id)
|
||||
})
|
||||
@ -20,7 +20,7 @@ describe("OceanBase", () => {
|
||||
it("should get the id", async () => {
|
||||
|
||||
const id = "test"
|
||||
const oceanBase = new OceanBase()
|
||||
const oceanBase = new OceanBaseMock()
|
||||
oceanBase.setId(id)
|
||||
|
||||
assert(oceanBase.getId() === id)
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as assert from "assert"
|
||||
import {assert} from "chai"
|
||||
import ConfigProvider from "../../src/ConfigProvider"
|
||||
import ContractHandler from "../../src/keeper/ContractHandler"
|
||||
import AccessStatus from "../../src/models/AccessStatus"
|
||||
|
Loading…
Reference in New Issue
Block a user