Skip to content

Commit

Permalink
refactor: migration scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
guidiaz committed Dec 17, 2021
1 parent ae317af commit c397618
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 144 deletions.
6 changes: 3 additions & 3 deletions migrations/scripts/1_deploy_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const prompt = require("prompt-sync")({ sigint: true })
const settings = require("../erc2362.settings")
const utils = require("../../scripts/utils")
const settings = require("../settings")

module.exports = async function (_deployer, network) {
network = network.split("-")[0]
Expand Down Expand Up @@ -30,7 +30,7 @@ Enjoy the power of the Witnet Decentralized Oracle Network ;-)
console.error(`\nFatal: no "test" configuration found for ${realm.toUpperCase()} realm! Please, review network settings.`)
process.exit(1)
}
let answer = prompt(`> Do you really want to run tests against ${realm.toUpperCase()} realm? [y/N] `).toLowerCase().trim()
let answer = (await utils.prompt(`> Do you really want to run tests against ${realm.toUpperCase()} realm? [y/N] `)).toLowerCase().trim()
if (!["y", "yes"].includes(answer)) {
console.log("\nInfo: cancelled by user.")
process.exit(0)
Expand Down
48 changes: 28 additions & 20 deletions migrations/witnet.requests.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,50 @@
},
"BtcUsdPrice": {
"bytecode": "0x0adb0312560801123a68747470733a2f2f6170692e62696e616e63652e636f6d2f6170692f76332f7469636b65722f70726963653f73796d626f6c3d425443555344541a168418778218646570726963658218571a000f4240185b124d0801122c68747470733a2f2f6170692e62697466696e65782e636f6d2f76312f7075627469636b65722f6274637573641a1b8418778218646a6c6173745f70726963658218571a000f4240185b12630801123268747470733a2f2f6170692e6b72616b656e2e636f6d2f302f7075626c69632f5469636b65723f706169723d4254435553441a2b87187782186666726573756c7482186668585842545a55534482186161618216008218571a000f4240185b12480801122d68747470733a2f2f7777772e6269747374616d702e6e65742f6170692f76322f7469636b65722f6274637573641a15841877821864646c6173748218571a000f4240185b12650801124068747470733a2f2f6170692e626974747265782e636f6d2f6170692f76312e312f7075626c69632f6765747469636b65723f6d61726b65743d5553442d4254431a1f85187782186666726573756c74821864644c6173748218571a000f4240185b1a0d0a0908051205fa402000001003220d0a0908051205fa40200000100310c0843d180a20c0843d28463080e497d012",
"decimals": 6,
"ERC2362ID": "Price-BTC/USD-6"
"base": "BTC",
"quote": "USD",
"decimals": 6
},
"CeloEurPrice": {
"bytecode": "0x0ad00212670801123768747470733a2f2f6170692e636f696e626173652e636f6d2f76322f65786368616e67652d72617465733f63757272656e63793d4555521a2a87187782186664646174618218666572617465738218646443474c44821859208218571a000f4240185b12660801124168747470733a2f2f6170692e626974747265782e636f6d2f6170692f76312e312f7075626c69632f6765747469636b65723f6d61726b65743d4555522d43454c4f1a1f85187782186666726573756c74821864644c6173748218571a000f4240185b125f0801122b68747470733a2f2f65786368616e67652d6170692e6c63782e636f6d2f6d61726b65742f7469636b6572731a2e86187782186664646174618218666843454c4f2f455552821864696c61737450726963658218571a000f4240185b1a0d0a0908051205fa402000001003220d0a0908051205fa40200000100310c0843d180a20c0843d28463080e497d012",
"decimals": 6,
"ERC2362ID": "Price-CELO/EUR-6"
"base": "CELO",
"quote": "EUR",
"decimals": 6
},
"CeloUsdPrice": {
"bytecode": "0x0acb0212670801123768747470733a2f2f6170692e636f696e626173652e636f6d2f76322f65786368616e67652d72617465733f63757272656e63793d5553441a2a87187782186664646174618218666572617465738218646443474c44821859208218571a000f4240185b12660801124168747470733a2f2f6170692e626974747265782e636f6d2f6170692f76312e312f7075626c69632f6765747469636b65723f6d61726b65743d5553442d43454c4f1a1f85187782186666726573756c74821864644c6173748218571a000f4240185b125a0801123768747470733a2f2f7777772e6f6b65782e636f6d2f6170692f696e6465782f76332f43454c4f2d5553442f636f6e7374697475656e74731a1d8518778218666464617461821864646c6173748218571a000f4240185b1a0d0a0908051205fa402000001003220d0a0908051205fa40200000100310c0843d180a20c0843d28463080e497d012",
"decimals": 6,
"ERC2362ID": "Price-CELO/USD-6"
"base": "CELO",
"quote": "USD",
"decimals": 6
},
"CfxUsdtPrice": {
"bytecode": "0x0a850312560801123a68747470733a2f2f6170692e62696e616e63652e636f6d2f6170692f76332f7469636b65722f70726963653f73796d626f6c3d434658555344541a168418778218646570726963658218571a000f4240185b12590801123668747470733a2f2f7777772e6f6b65782e636f6d2f6170692f696e6465782f76332f4346582d5553442f636f6e7374697475656e74731a1d8518778218666464617461821864646c6173748218571a000f4240185b12490801122e68747470733a2f2f646174612e676174656170692e696f2f617069322f312f7469636b65722f6366785f757364741a15841877821864646c6173748218571a000f4240185b12670801123e68747470733a2f2f7777772e6d6578632e636f6d2f6f70656e2f6170692f76322f6d61726b65742f7469636b65723f73796d626f6c3d4346585f555344541a23871877821861646461746182181800821867646c61737418728218571a000f4240185b1a0d0a0908051205fa402000001003220d0a0908051205fa40200000100310c0843d180a20c0843d28463080e497d012",
"decimals": 6,
"ERC2362ID": "Price-CFX/USDT-6"
"bytecode": "0x0a840312560801123a68747470733a2f2f6170692e62696e616e63652e636f6d2f6170692f76332f7469636b65722f70726963653f73796d626f6c3d434658555344541a168418778218646570726963658218571a000f4240185b12590801123668747470733a2f2f7777772e6f6b65782e636f6d2f6170692f696e6465782f76332f4346582d5553442f636f6e7374697475656e74731a1d8518778218666464617461821864646c6173748218571a000f4240185b12490801122e68747470733a2f2f646174612e676174656170692e696f2f617069322f312f7469636b65722f6366785f757364741a15841877821864646c6173748218571a000f4240185b12660801123d68747470733a2f2f7777772e6d78632e636f6d2f6f70656e2f6170692f76322f6d61726b65742f7469636b65723f73796d626f6c3d4346585f555344541a23871877821861646461746182181800821867646c61737418728218571a000f4240185b1a0d0a0908051205fa402000001003220d0a0908051205fa40200000100310c0843d180a20c0843d28463080e497d012",
"base": "CFX",
"quote": "USDT",
"decimals": 6
},
"EthUsdPrice": {
"bytecode": "0x0adb0312560801123a68747470733a2f2f6170692e62696e616e63652e636f6d2f6170692f76332f7469636b65722f70726963653f73796d626f6c3d455448555344541a168418778218646570726963658218571a000f4240185b124d0801122c68747470733a2f2f6170692e62697466696e65782e636f6d2f76312f7075627469636b65722f4554485553441a1b8418778218646a6c6173745f70726963658218571a000f4240185b12630801123268747470733a2f2f6170692e6b72616b656e2e636f6d2f302f7075626c69632f5469636b65723f706169723d4554485553441a2b87187782186666726573756c7482186668584554485a55534482186161618216008218571a000f4240185b12480801122d68747470733a2f2f7777772e6269747374616d702e6e65742f6170692f76322f7469636b65722f6574687573641a15841877821864646c6173748218571a000f4240185b12650801124068747470733a2f2f6170692e626974747265782e636f6d2f6170692f76312e312f7075626c69632f6765747469636b65723f6d61726b65743d5553442d4554481a1f85187782186666726573756c74821864644c6173748218571a000f4240185b1a0d0a0908051205fa402000001003220d0a0908051205fa40200000100310c0843d180a20c0843d28463080e497d012",
"decimals": 6,
"ERC2362ID": "Price-ETH/USD-6"
"base": "ETH",
"quote": "USD",
"decimals": 6
},
"OmgBtcPrice": {
"bytecode": "0x0aa40412490801122e68747470733a2f2f7777772e6269747374616d702e6e65742f6170692f76322f7469636b65722f6f6d676274632f1a15841877821864646c6173748218571a3b9aca00185b12550801123968747470733a2f2f6170692e62696e616e63652e636f6d2f6170692f76332f7469636b65722f70726963653f73796d626f6c3d4f4d474254431a168418778218646570726963658218571a3b9aca00185b12480801122d68747470733a2f2f646174612e676174656170692e696f2f617069322f312f7469636b65722f6f6d675f6274631a15841877821864646c6173748218571a3b9aca00185b12660801123d68747470733a2f2f7777772e6d6578632e636f6d2f6f70656e2f6170692f76322f6d61726b65742f7469636b65723f73796d626f6c3d4f4d475f4254431a23871877821861646461746182181800821867646c61737418728218571a3b9aca00185b124d0801122c68747470733a2f2f6170692e62697466696e65782e636f6d2f76312f7075627469636b65722f6f6d676274631a1b8418778218646a6c6173745f70726963658218571a3b9aca00185b12610801123268747470733a2f2f6170692e6b72616b656e2e636f6d2f302f7075626c69632f5469636b65723f706169723d4f4d474254431a2987187782186666726573756c74821866664f4d4758425482186161618216008218571a3b9aca00185b1a0d0a0908051205fa402000001003220d0a0908051205fa40200000100310c0843d180a20c0843d28463080e497d012",
"decimals": 9,
"ERC2362ID": "Price-OMG/BTC-9"
"bytecode": "0x0aa30412490801122e68747470733a2f2f7777772e6269747374616d702e6e65742f6170692f76322f7469636b65722f6f6d676274632f1a15841877821864646c6173748218571a3b9aca00185b12550801123968747470733a2f2f6170692e62696e616e63652e636f6d2f6170692f76332f7469636b65722f70726963653f73796d626f6c3d4f4d474254431a168418778218646570726963658218571a3b9aca00185b12480801122d68747470733a2f2f646174612e676174656170692e696f2f617069322f312f7469636b65722f6f6d675f6274631a15841877821864646c6173748218571a3b9aca00185b12650801123c68747470733a2f2f7777772e6d78632e636f6d2f6f70656e2f6170692f76322f6d61726b65742f7469636b65723f73796d626f6c3d4f4d475f4254431a23871877821861646461746182181800821867646c61737418728218571a3b9aca00185b124d0801122c68747470733a2f2f6170692e62697466696e65782e636f6d2f76312f7075627469636b65722f6f6d676274631a1b8418778218646a6c6173745f70726963658218571a3b9aca00185b12610801123268747470733a2f2f6170692e6b72616b656e2e636f6d2f302f7075626c69632f5469636b65723f706169723d4f4d474254431a2987187782186666726573756c74821866664f4d4758425482186161618216008218571a3b9aca00185b1a0d0a0908051205fa402000001003220d0a0908051205fa40200000100310c0843d180a20c0843d28463080e497d012",
"base": "OMG",
"quote": "BTC",
"decimals": 9
},
"OmgEthPrice": {
"bytecode": "0x0a850412550801123968747470733a2f2f6170692e62696e616e63652e636f6d2f6170692f76332f7469636b65722f70726963653f73796d626f6c3d4f4d474554481a168418778218646570726963658218571a3b9aca00185b12480801122d68747470733a2f2f646174612e676174656170692e696f2f617069322f312f7469636b65722f6f6d675f6574681a15841877821864646c6173748218571a3b9aca00185b1291010801125a68747470733a2f2f646174612e6d6573736172692e696f2f6170692f76312f6173736574732f6f6d672f6d6574726963732f6d61726b65742d646174613f6669656c64733d6d61726b65745f646174612f70726963655f6574681a3186187782186664646174618218666b6d61726b65745f646174618218646970726963655f6574688218571a3b9aca00185b124d0801122c68747470733a2f2f6170692e62697466696e65782e636f6d2f76312f7075627469636b65722f6f6d676574681a1b8418778218646a6c6173745f70726963658218571a3b9aca00185b12610801123268747470733a2f2f6170692e6b72616b656e2e636f6d2f302f7075626c69632f5469636b65723f706169723d4f4d474554481a2987187782186666726573756c74821866664f4d4745544882186161618216008218571a3b9aca00185b1a0d0a0908051205fa402000001003220d0a0908051205fa40200000100310c0843d180a20c0843d28463080e497d012",
"decimals": 9,
"ERC2362ID": "Price-OMG/ETH-9"
"bytecode": "0x0ae20412550801123968747470733a2f2f6170692e62696e616e63652e636f6d2f6170692f76332f7469636b65722f70726963653f73796d626f6c3d4f4d474554481a168418778218646570726963658218571a3b9aca00185b12480801122d68747470733a2f2f646174612e676174656170692e696f2f617069322f312f7469636b65722f6f6d675f6574681a15841877821864646c6173748218571a3b9aca00185b125b0801123f68747470733a2f2f636f696e7965702e636f6d2f6170692f76312f3f66726f6d3d4f4d4726746f3d455448266c616e673d657326666f726d61743d6a736f6e1a168418778218646570726963658218571a3b9aca00185b1291010801125a68747470733a2f2f646174612e6d6573736172692e696f2f6170692f76312f6173736574732f6f6d672f6d6574726963732f6d61726b65742d646174613f6669656c64733d6d61726b65745f646174612f70726963655f6574681a3186187782186664646174618218666b6d61726b65745f646174618218646970726963655f6574688218571a3b9aca00185b124d0801122c68747470733a2f2f6170692e62697466696e65782e636f6d2f76312f7075627469636b65722f6f6d676574681a1b8418778218646a6c6173745f70726963658218571a3b9aca00185b12610801123268747470733a2f2f6170692e6b72616b656e2e636f6d2f302f7075626c69632f5469636b65723f706169723d4f4d474554481a2987187782186666726573756c74821866664f4d4745544882186161618216008218571a3b9aca00185b1a0d0a0908051205fa402000001003220d0a0908051205fa40200000100310c0843d180a20c0843d28463080e497d012",
"base": "OMG",
"quote": "ETH",
"decimals": 9
},
"OmgUsdtPrice": {
"bytecode": "0x0a860312560801123a68747470733a2f2f6170692e62696e616e63652e636f6d2f6170692f76332f7469636b65722f70726963653f73796d626f6c3d4f4d47555344541a168418778218646570726963658218571a000f4240185b125a0801123768747470733a2f2f7777772e6f6b65782e636f6d2f6170692f696e6465782f76332f4f4d472d555344542f636f6e7374697475656e74731a1d8518778218666464617461821864646c6173748218571a000f4240185b12490801122e68747470733a2f2f646174612e676174656170692e696f2f617069322f312f7469636b65722f6f6d675f757364741a15841877821864646c6173748218571a000f4240185b12670801123e68747470733a2f2f7777772e6d6578632e636f6d2f6f70656e2f6170692f76322f6d61726b65742f7469636b65723f73796d626f6c3d4f4d475f555344541a23871877821861646461746182181800821867646c61737418728218571a000f4240185b1a0d0a0908051205fa402000001003220d0a0908051205fa40200000100310c0843d180a20c0843d28463080e497d012",
"decimals": 6,
"ERC2362ID": "Price-OMG/USDT-6"
"bytecode": "0x0a850312560801123a68747470733a2f2f6170692e62696e616e63652e636f6d2f6170692f76332f7469636b65722f70726963653f73796d626f6c3d4f4d47555344541a168418778218646570726963658218571a000f4240185b125a0801123768747470733a2f2f7777772e6f6b65782e636f6d2f6170692f696e6465782f76332f4f4d472d555344542f636f6e7374697475656e74731a1d8518778218666464617461821864646c6173748218571a000f4240185b12490801122e68747470733a2f2f646174612e676174656170692e696f2f617069322f312f7469636b65722f6f6d675f757364741a15841877821864646c6173748218571a000f4240185b12660801123d68747470733a2f2f7777772e6d78632e636f6d2f6f70656e2f6170692f76322f6d61726b65742f7469636b65723f73796d626f6c3d4f4d475f555344541a23871877821861646461746182181800821867646c61737418728218571a000f4240185b1a0d0a0908051205fa402000001003220d0a0908051205fa40200000100310c0843d180a20c0843d28463080e497d012",
"base": "OMG",
"quote": "USDT",
"decimals": 6
}
}
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@
"ado-contracts": "^1.0.0",
"lodash": "^4.17.21",
"openzeppelin-solidity": "^2.4.0",
"prompt-sync": "^4.2.0",
"witnet-solidity-bridge": "~0.5.0",
"witnet-requests": "~0.7.3"
"witnet-solidity-bridge": "git+https://github.com/witnet/witnet-solidity-bridge#feat/witnet-price-registry",
"witnet-requests": "~0.7.0"
},
"devDependencies": {
"dotenv": "8.2.0",
Expand Down
80 changes: 52 additions & 28 deletions scripts/flattened-migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ const fs = require("fs")
const os = require("os")
const cli = new cli_func()

const settings = require("../migrations/erc2362.settings")
const templateScript = "migrations.erc2362.template.js"
const outputScript = "1_price_feed_examples.js"
const settings = require("../migrations/settings")
const templateScript = "migrations.template.js"
const outputScript = "1_deploy_poller.js"

if (process.argv.length < 3) {
console.log()
Expand All @@ -38,8 +38,8 @@ if (!settings.networks[realm] || !settings.networks[realm][network]) {
}

const artifact = settings.artifacts[realm]
? settings.artifacts[realm].ERC2362PriceFeed
: settings.artifacts.default.ERC2362PriceFeed
? settings.artifacts[realm].WitnetPricePoller
: settings.artifacts.default.WitnetPricePoller

process.env.FLATTENED_DIRECTORY = `./flattened/${artifact}/`

Expand All @@ -49,19 +49,16 @@ if (!fs.existsSync(`${process.env.FLATTENED_DIRECTORY}/Flattened${artifact}.sol`
process.exit(0)
}

compileFlattened().then(() => {
composeMigrationScript(artifact)
migrateFlattened(network).then(() => {
deleteMigrationScript()
console.log()
composeMigrationScript(artifact)
migrateFlattened(network).then(() => {
deleteMigrationScript()
console.log()
})
})
.catch(err => {
console.error("Fatal:", err)
console.error()
process.exit(-1)
})
.catch(err => {
console.error("Fatal:", err)
console.error()
process.exit(-1)
})

/// /////////////////////////////////////////////////////////////////////////////

Expand All @@ -81,21 +78,48 @@ function cli_func () {

async function migrateFlattened (network) {
console.log(`> Migrating from ${process.env.FLATTENED_DIRECTORY} into network '${network}'...`)
await cli.exec(`truffle migrate --reset --config truffle-config.flattened.js --network ${network}`)
.catch(err => {
console.error(err)
process.exit(-2)
// await cli.exec(`truffle migrate --reset --config truffle-config.flattened.js --network ${network}`)
// .catch(err => {
// console.error(err)
// process.exit(-2)
// })

await new Promise((resolve) => {
const subprocess = require("child_process").spawn(
"truffle",
[
"migrate",
"--reset",
"--config",
"truffle-config.flattened.js",
"--network",
network,
],
{
shell: true,
stdin: "inherit",
}
)
process.stdin.pipe(subprocess.stdin)
subprocess.stdout.pipe(process.stdout)
subprocess.stderr.pipe(process.stderr)
subprocess.on("close", (code) => {
if (code !== 0) {
process.exit(code)
}
resolve(subprocess.stdout)
})
})
}

async function compileFlattened () {
console.log(`\n> Compiling from ${process.env.FLATTENED_DIRECTORY}...`)
await cli.exec("truffle compile --all --config truffle-config.flattened.js")
.catch(err => {
console.error(err)
process.exit(-1)
})
}
// async function compileFlattened () {
// console.log(`\n> Compiling from ${process.env.FLATTENED_DIRECTORY}...`)
// await cli.exec("truffle compile --all --config truffle-config.flattened.js")
// .catch(err => {
// console.error(err)
// process.exit(-1)
// })
// }

function composeMigrationScript (artifact) {
let templateFile = `./scripts/templates/${templateScript}`
Expand Down
Loading

0 comments on commit c397618

Please sign in to comment.