mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
simulating zos on contract deployment
This commit is contained in:
parent
26e6c534a0
commit
dd2b672adb
@ -26,49 +26,24 @@ export default class TestContractHandler extends ContractHandler {
|
|||||||
private static async deployContracts(deployerAddress: string) {
|
private static async deployContracts(deployerAddress: string) {
|
||||||
Logger.log("Trying to deploy contracts")
|
Logger.log("Trying to deploy contracts")
|
||||||
|
|
||||||
// deploy libs
|
const token = await TestContractHandler.deployContract("OceanToken", deployerAddress, [deployerAddress])
|
||||||
/* not part of trilobite
|
|
||||||
const dll = await ContractHandler.deployContract("DLL", deployerAddress)
|
|
||||||
const attributeStore = await ContractHandler.deployContract("AttributeStore", deployerAddress)
|
|
||||||
*/
|
|
||||||
// deploy contracts
|
|
||||||
const token = await TestContractHandler.deployContract("OceanToken", deployerAddress)
|
|
||||||
/* not part of trilobite
|
|
||||||
const plcrVoting = await ContractHandler.deployContract("PLCRVoting", deployerAddress, {
|
|
||||||
args: [token.options.address],
|
|
||||||
tokens: [
|
|
||||||
{
|
|
||||||
name: "DLL", address: dll.options.address,
|
|
||||||
}, {
|
|
||||||
name: "AttributeStore", address: attributeStore.options.address,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
|
||||||
/* not part of trilobite
|
|
||||||
const registry = await ContractHandler.deployContract("OceanRegistry", deployerAddress, {
|
|
||||||
args: [token.options.address, plcrVoting.options.address],
|
|
||||||
})
|
|
||||||
*/
|
|
||||||
await TestContractHandler.deployContract("Dispenser", deployerAddress, {
|
|
||||||
args: [token.options.address],
|
|
||||||
})
|
|
||||||
|
|
||||||
const sa = await TestContractHandler.deployContract("ServiceExecutionAgreement", deployerAddress, {
|
const dispenser = await TestContractHandler.deployContract("Dispenser", deployerAddress, [token.options.address, deployerAddress])
|
||||||
args: [],
|
|
||||||
})
|
|
||||||
|
|
||||||
await TestContractHandler.deployContract("AccessConditions", deployerAddress, {
|
// Add dispenser as Token minter
|
||||||
args: [sa.options.address],
|
await token.methods.addMinter(dispenser.options.address)
|
||||||
})
|
.send({from: deployerAddress})
|
||||||
|
|
||||||
await TestContractHandler.deployContract("PaymentConditions", deployerAddress, {
|
const sa = await TestContractHandler.deployContract("ServiceExecutionAgreement", deployerAddress)
|
||||||
args: [sa.options.address, token.options.address],
|
|
||||||
})
|
|
||||||
|
|
||||||
await TestContractHandler.deployContract("DIDRegistry", deployerAddress, {})
|
await TestContractHandler.deployContract("AccessConditions", deployerAddress, [sa.options.address])
|
||||||
|
|
||||||
|
await TestContractHandler.deployContract("PaymentConditions", deployerAddress, [sa.options.address, token.options.address])
|
||||||
|
|
||||||
|
await TestContractHandler.deployContract("DIDRegistry", deployerAddress, [deployerAddress])
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async deployContract(name: string, from: string, params?): Promise<Contract> {
|
private static async deployContract(name: string, from: string, args: any[] = []): Promise<Contract> {
|
||||||
|
|
||||||
// dont redeploy if there is already something loaded
|
// dont redeploy if there is already something loaded
|
||||||
if (ContractHandler.has(name)) {
|
if (ContractHandler.has(name)) {
|
||||||
@ -80,39 +55,30 @@ export default class TestContractHandler extends ContractHandler {
|
|||||||
let contractInstance: Contract
|
let contractInstance: Contract
|
||||||
try {
|
try {
|
||||||
Logger.log("Deploying", name)
|
Logger.log("Deploying", name)
|
||||||
|
const sendConfig = {
|
||||||
const artifact = require(`@oceanprotocol/keeper-contracts/artifacts/${name}.development.json`)
|
|
||||||
const tempContract = new web3.eth.Contract(artifact.abi, artifact.address)
|
|
||||||
contractInstance = await tempContract.deploy({
|
|
||||||
data: params && params.tokens ?
|
|
||||||
TestContractHandler.replaceTokens(artifact.bytecode.toString(), params.tokens) :
|
|
||||||
artifact.bytecode,
|
|
||||||
arguments: params && params.args ? params.args : null,
|
|
||||||
}).send({
|
|
||||||
from,
|
from,
|
||||||
gas: 3000000,
|
gas: 3000000,
|
||||||
gasPrice: 10000000000,
|
gasPrice: 10000000000,
|
||||||
})
|
}
|
||||||
|
const artifact = require(`@oceanprotocol/keeper-contracts/artifacts/${name}.development.json`)
|
||||||
|
const tempContract = new web3.eth.Contract(artifact.abi, artifact.address)
|
||||||
|
const isZos = !!tempContract.methods.initialize
|
||||||
|
contractInstance = await tempContract
|
||||||
|
.deploy({
|
||||||
|
data: artifact.bytecode,
|
||||||
|
arguments: isZos ? undefined : args,
|
||||||
|
})
|
||||||
|
.send(sendConfig)
|
||||||
|
if (isZos) {
|
||||||
|
await contractInstance.methods.initialize(...args).send(sendConfig)
|
||||||
|
}
|
||||||
TestContractHandler.set(name, contractInstance)
|
TestContractHandler.set(name, contractInstance)
|
||||||
// Logger.log("Deployed", name, "at", contractInstance.options.address);
|
// Logger.log("Deployed", name, "at", contractInstance.options.address);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Logger.error("Deployment failed for", name, "with params", JSON.stringify(params, null, 2), err.message)
|
Logger.error("Deployment failed for", name, "with args", JSON.stringify(args, null, 2), err.message)
|
||||||
throw err
|
throw err
|
||||||
}
|
}
|
||||||
|
|
||||||
return contractInstance
|
return contractInstance
|
||||||
}
|
}
|
||||||
|
|
||||||
private static replaceTokens(bytecode: string, tokens: any[]) {
|
|
||||||
|
|
||||||
for (const token of tokens) {
|
|
||||||
|
|
||||||
bytecode = bytecode.replace(
|
|
||||||
new RegExp(`_+${token.name}_+`, "g"),
|
|
||||||
token.address.replace("0x", ""))
|
|
||||||
}
|
|
||||||
// Logger.log(bytecode)
|
|
||||||
|
|
||||||
return bytecode.toString()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user