Skip to content

Commit

Permalink
harmony-one#99 all tests passed: ensure contracts deploy with linked …
Browse files Browse the repository at this point in the history
…libraries
  • Loading branch information
hashmesan committed Apr 25, 2022
1 parent 2457ed7 commit f40af1a
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 24 deletions.
8 changes: 2 additions & 6 deletions contract/bridge/test/Issue.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ const { expectRevert } = require("@openzeppelin/test-helpers");
const { web3 } = require("@openzeppelin/test-helpers/src/setup");
const { deployProxy } = require("@openzeppelin/truffle-upgrades");

const OneBtc = artifacts.require("OneBtc");
const RelayMock = artifacts.require("RelayMock");
const ExchangeRateOracleWrapper = artifacts.require("ExchangeRateOracleWrapper");
const deployHelper = require("./helpers/deploy");
const { issueTxMock } = require("./mock/btcTxMock");

const bitcoin = require("bitcoinjs-lib");
Expand All @@ -29,9 +27,7 @@ web3.extend({

contract("Issue unit test", (accounts) => {
before(async function () {
this.RelayMock = await RelayMock.new();
this.ExchangeRateOracleWrapper = await deployProxy(ExchangeRateOracleWrapper);
this.OneBtc = await deployProxy(OneBtc, [this.RelayMock.address, this.ExchangeRateOracleWrapper.address]);
({oneBtc: this.OneBtc, relayMock: this.RelayMock, exchangeRateOracleWrapper: this.ExchangeRateOracleWrapper} = await deployHelper.deployOneBTC());

// set BTC/ONE exchange rate
await this.ExchangeRateOracleWrapper.setExchangeRate(10); // 1 OneBtc = 10 ONE
Expand Down
4 changes: 4 additions & 0 deletions contract/bridge/test/KeyDerivation.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const bitcoin = require('bitcoinjs-lib');
const ecc = require('tiny-secp256k1');
const Secp256k1 = artifacts.require("Secp256k1");

const BitcoinKeyDerivationMock = artifacts.require("BitcoinKeyDerivationMock");

Expand All @@ -26,6 +27,9 @@ function derivate(priD, id) {

contract("BitcoinKeyDerivation:On-Chain Key Derivation Scheme", accounts => {
it("key derivate", async () => {
const Secp256k1Lib = await Secp256k1.new();
BitcoinKeyDerivationMock.link("Secp256k1", Secp256k1Lib.address);

const keyDervation = await BitcoinKeyDerivationMock.new();
for(let i = 0; i < 100; i++) {
const ecPair = bitcoin.ECPair.makeRandom({compressed:false});
Expand Down
8 changes: 2 additions & 6 deletions contract/bridge/test/OneBTC.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ const { expectRevert } = require("@openzeppelin/test-helpers");
const { web3 } = require("@openzeppelin/test-helpers/src/setup");
const { deployProxy } = require("@openzeppelin/truffle-upgrades");

const OneBtc = artifacts.require("OneBtc");
const RelayMock = artifacts.require("RelayMock");
const ExchangeRateOracleWrapper = artifacts.require("ExchangeRateOracleWrapper");
const deployHelper = require("./helpers/deploy");
const { issueTxMock } = require('./mock/btcTxMock');

const bitcoin = require('bitcoinjs-lib');
Expand All @@ -29,9 +27,7 @@ web3.extend({

contract("issue/redeem test", accounts => {
before(async function() {
this.RelayMock = await RelayMock.new();
this.ExchangeRateOracleWrapper = await deployProxy(ExchangeRateOracleWrapper);
this.OneBtc = await deployProxy(OneBtc, [this.RelayMock.address, this.ExchangeRateOracleWrapper.address],{initializer: false, unsafeAllowLinkedLibraries: true});
({oneBtc: this.OneBtc, relayMock: this.RelayMock, exchangeRateOracleWrapper: this.ExchangeRateOracleWrapper} = await deployHelper.deployOneBTC());

// set BTC/ONE exchange rate
await this.ExchangeRateOracleWrapper.setExchangeRate(10); // 1 OneBtc = 10 ONE
Expand Down
8 changes: 2 additions & 6 deletions contract/bridge/test/Redeem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ const { expectRevert } = require("@openzeppelin/test-helpers");
const { web3 } = require("@openzeppelin/test-helpers/src/setup");
const { deployProxy } = require("@openzeppelin/truffle-upgrades");

const OneBtc = artifacts.require("OneBtc");
const RelayMock = artifacts.require("RelayMock");
const ExchangeRateOracleWrapper = artifacts.require("ExchangeRateOracleWrapper");
const deployHelper = require("./helpers/deploy");
const { issueTxMock } = require("./mock/btcTxMock");

const bitcoin = require("bitcoinjs-lib");
Expand All @@ -29,9 +27,7 @@ web3.extend({

contract("Redeem unit test", (accounts) => {
before(async function () {
this.RelayMock = await RelayMock.new();
this.ExchangeRateOracleWrapper = await deployProxy(ExchangeRateOracleWrapper);
this.OneBtc = await deployProxy(OneBtc, [this.RelayMock.address, this.ExchangeRateOracleWrapper.address]);
({oneBtc: this.OneBtc, relayMock: this.RelayMock, exchangeRateOracleWrapper: this.ExchangeRateOracleWrapper} = await deployHelper.deployOneBTC());

// set BTC/ONE exchange rate
await this.ExchangeRateOracleWrapper.setExchangeRate(10); // 1 OneBtc = 10 ONE
Expand Down
8 changes: 2 additions & 6 deletions contract/bridge/test/Replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ const { expectRevert } = require("@openzeppelin/test-helpers");
const { web3 } = require("@openzeppelin/test-helpers/src/setup");
const { deployProxy } = require("@openzeppelin/truffle-upgrades");

const OneBtc = artifacts.require("OneBtc");
const RelayMock = artifacts.require("RelayMock");
const ExchangeRateOracleWrapper = artifacts.require("ExchangeRateOracleWrapper");
const deployHelper = require("./helpers/deploy");
const { issueTxMock } = require("./mock/btcTxMock");

const bitcoin = require("bitcoinjs-lib");
Expand All @@ -29,9 +27,7 @@ web3.extend({

contract("Replace unit test", (accounts) => {
before(async function () {
this.RelayMock = await RelayMock.new();
this.ExchangeRateOracleWrapper = await deployProxy(ExchangeRateOracleWrapper);
this.OneBtc = await deployProxy(OneBtc, [this.RelayMock.address, this.ExchangeRateOracleWrapper.address]);
({oneBtc: this.OneBtc, relayMock: this.RelayMock, exchangeRateOracleWrapper: this.ExchangeRateOracleWrapper} = await deployHelper.deployOneBTC());

// set BTC/ONE exchange rate
await this.ExchangeRateOracleWrapper.setExchangeRate(10); // 1 OneBtc = 10 ONE
Expand Down
3 changes: 3 additions & 0 deletions contract/bridge/test/TxValidate.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const TxUtils = artifacts.require("TransactionUtilsMock");
const TxValidate = artifacts.require("TxValidateMock");
const TxValidateLibA = artifacts.require("TxValidate");

const bitcoin = require('bitcoinjs-lib');
const { expectRevert } = require("@openzeppelin/test-helpers");
Expand All @@ -8,6 +9,8 @@ const { issueTxMock } = require('./mock/btcTxMock');
contract("transaction parse test", accounts => {
it("extractTx and validateTxout", async () => {
const txUtils = await TxUtils.new();
const TxValidateLib = await TxValidateLibA.new();
TxValidate.link("TxValidate", TxValidateLib.address);
const txValidate = await TxValidate.new();
const receiverAddress = '12L1QTVLowqsRUNht35RyBE3RZzmCZzYF3';
const requestId = 123;
Expand Down
7 changes: 7 additions & 0 deletions contract/bridge/test/VaultRegistry.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const VaultRegistryTestWrapper = artifacts.require("VaultRegistryTestWrapper");
const bitcoin = require("bitcoinjs-lib");
const bn = (b) => BigInt(`0x${b.toString("hex")}`);
const Secp256k1 = artifacts.require("Secp256k1");
const TxValidate = artifacts.require("TxValidate");

web3.extend({
property: "miner",
Expand All @@ -20,6 +22,11 @@ web3.extend({

contract("VaultRegistry unit test", (accounts) => {
before(async function () {
const Secp256k1Lib = await Secp256k1.new();
VaultRegistryTestWrapper.link("Secp256k1", Secp256k1Lib.address);

const TxValidateLib = await TxValidate.new();
VaultRegistryTestWrapper.link("TxValidate", TxValidateLib.address);
this.VaultRegistry = await VaultRegistryTestWrapper.new();

this.vaultId = accounts[1];
Expand Down
27 changes: 27 additions & 0 deletions contract/bridge/test/helpers/deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

const { deployProxy } = require("@openzeppelin/truffle-upgrades");

const OneBtc = artifacts.require("OneBtc");
const RelayMock = artifacts.require("RelayMock");
const ExchangeRateOracleWrapper = artifacts.require("ExchangeRateOracleWrapper");
const Secp256k1 = artifacts.require("Secp256k1");
const TxValidate = artifacts.require("TxValidate");

async function deployOneBTC() {
const relayMock = await RelayMock.new();
const exchangeRateOracleWrapper = await deployProxy(ExchangeRateOracleWrapper);

const Secp256k1Lib = await Secp256k1.new();
OneBtc.link("Secp256k1", Secp256k1Lib.address);

const TxValidateLib = await TxValidate.new();
OneBtc.link("TxValidate", TxValidateLib.address);

const oneBtc = await deployProxy(OneBtc, [RelayMock.address, ExchangeRateOracleWrapper.address],{unsafeAllowLinkedLibraries: true});

return {oneBtc, relayMock, exchangeRateOracleWrapper}
}

module.exports = {
deployOneBTC
}

0 comments on commit f40af1a

Please sign in to comment.