From 7a70235f02aae38589423039c0d1c1bfc185f915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20D=C3=ADaz?= Date: Mon, 5 Aug 2024 18:07:51 +0200 Subject: [PATCH] fix: migrations and tests --- .../core/trustable/WitOracleTrustableBase.sol | 2 - .../WitOracleRadonRegistryDefault.sol | 4 +- migrations/scripts/3_core.js | 2 +- migrations/scripts/4_proxies.js | 2 +- test/TestWitOracleRadonEncodingLib.sol | 4 +- test/{TestWitnetV2.sol => TestWitnet.sol} | 0 test/mocks/WitMockedRandomness.sol | 2 +- ...test.js => witOracleRadonRegistry.spec.js} | 394 +++++------------- 8 files changed, 102 insertions(+), 308 deletions(-) rename test/{TestWitnetV2.sol => TestWitnet.sol} (100%) rename test/{witnet_bytecodes.test.js => witOracleRadonRegistry.spec.js} (57%) diff --git a/contracts/core/trustable/WitOracleTrustableBase.sol b/contracts/core/trustable/WitOracleTrustableBase.sol index 74160ab8..b596dc44 100644 --- a/contracts/core/trustable/WitOracleTrustableBase.sol +++ b/contracts/core/trustable/WitOracleTrustableBase.sol @@ -206,8 +206,6 @@ abstract contract WitOracleTrustableBase _require(address(registry).code.length > 0, "inexistent registry"); _require(registry.specs() == type(WitOracleRadonRegistry).interfaceId, "uncompliant registry"); - _require(address(factory).code.length > 0, "inexistent factory"); - _require(address(factory.witOracle()) == address(this), "discordant factory"); // Set reporters, if any __setReporters(_newReporters); diff --git a/contracts/core/trustless/WitOracleRadonRegistryDefault.sol b/contracts/core/trustless/WitOracleRadonRegistryDefault.sol index ae867184..9acb9c15 100644 --- a/contracts/core/trustless/WitOracleRadonRegistryDefault.sol +++ b/contracts/core/trustless/WitOracleRadonRegistryDefault.sol @@ -164,8 +164,8 @@ contract WitOracleRadonRegistryDefault // --- Implementation of 'IWitOracleRadonRegistry' ----------------------------------------------------------------------- function bytecodeOf(bytes32 _radHash) - public view - override + public view override + radonRequestExists(_radHash) returns (bytes memory) { return __database().radsBytecode[_radHash]; diff --git a/migrations/scripts/3_core.js b/migrations/scripts/3_core.js index 1cce444e..e28a36bb 100644 --- a/migrations/scripts/3_core.js +++ b/migrations/scripts/3_core.js @@ -43,7 +43,7 @@ module.exports = async function (_, network, [, from]) { libs: specs.WitOracleRequestFactory.libs, immutables: specs.WitOracleRequestFactory.immutables, intrinsics: { - types: ["address", "address", "bool", "bytes32"], + types: ["address", "bool", "bytes32"], values: [ /* _witOracle */ await determineProxyAddr(from, specs.WitOracle?.vanity || 3), /* _upgradable */ true, diff --git a/migrations/scripts/4_proxies.js b/migrations/scripts/4_proxies.js index d3266029..96ff0e0c 100644 --- a/migrations/scripts/4_proxies.js +++ b/migrations/scripts/4_proxies.js @@ -18,8 +18,8 @@ module.exports = async function (_, network, [, from, reporter]) { const singletons = [ "WitOracleRadonRegistry", - "WitOracleRequestFactory", "WitOracle", + "WitOracleRequestFactory", "WitPriceFeeds", ] diff --git a/test/TestWitOracleRadonEncodingLib.sol b/test/TestWitOracleRadonEncodingLib.sol index b7e8cecf..6741fb72 100644 --- a/test/TestWitOracleRadonEncodingLib.sol +++ b/test/TestWitOracleRadonEncodingLib.sol @@ -88,7 +88,7 @@ contract TestWitOracleRadonEncodingLib { Witnet.RadonRetrieval memory source; source.method = Witnet.RadonRetrievalMethods.HttpGet; source.url = "https://data.messar.io/api/v1/assets/\\0\\/metrics/market-data?fields=market_data/price_\\1\\"; - source.script = hex"861877821866646461746182186664706f6f6c8218646b746f6b656e3150726963658218571a000f4240185b"; + source.radonScript = hex"861877821866646461746182186664706f6f6c8218646b746f6b656e3150726963658218571a000f4240185b"; bytes memory bytecode = WitOracleRadonEncodingLib.encode(source); // emit Log(bytecode); Assert.equal( @@ -106,7 +106,7 @@ contract TestWitOracleRadonEncodingLib { source.headers = new string[2][](2); source.headers[0] = [ "user-agent", "witnet-rust" ]; source.headers[1] = [ "content-type", "text/html; charset=utf-8" ]; - source.script = hex"861877821866646461746182186664706f6f6c8218646b746f6b656e3150726963658218571a000f4240185b"; + source.radonScript = hex"861877821866646461746182186664706f6f6c8218646b746f6b656e3150726963658218571a000f4240185b"; bytes memory bytecode = WitOracleRadonEncodingLib.encode(source); // emit Log(bytecode); Assert.equal( diff --git a/test/TestWitnetV2.sol b/test/TestWitnet.sol similarity index 100% rename from test/TestWitnetV2.sol rename to test/TestWitnet.sol diff --git a/test/mocks/WitMockedRandomness.sol b/test/mocks/WitMockedRandomness.sol index d9dace25..bac876a6 100644 --- a/test/mocks/WitMockedRandomness.sol +++ b/test/mocks/WitMockedRandomness.sol @@ -1,4 +1,4 @@ -ยบ// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: MIT pragma solidity >=0.7.0 <0.9.0; pragma experimental ABIEncoderV2; diff --git a/test/witnet_bytecodes.test.js b/test/witOracleRadonRegistry.spec.js similarity index 57% rename from test/witnet_bytecodes.test.js rename to test/witOracleRadonRegistry.spec.js index ffc22c51..cb4fc8f9 100644 --- a/test/witnet_bytecodes.test.js +++ b/test/witOracleRadonRegistry.spec.js @@ -1,6 +1,7 @@ +import("chai") + const utils = require("../src/utils") const { expectEvent, expectRevert } = require("@openzeppelin/test-helpers") -const { assert } = require("chai") const { expectRevertCustomError } = require("custom-error-test-helper") const WitOracleRadonRegistry = artifacts.require("WitOracleRadonRegistryDefault") @@ -12,11 +13,11 @@ contract("WitOracleRadonRegistry", (accounts) => { const firstOwnerAddress = accounts[1] const unprivilegedAddress = accounts[4] - let bytecodes + let radonRegistry before(async () => { await WitOracleRadonRegistry.link(WitOracleRadonEncodingLib, WitOracleRadonEncodingLib.address) - bytecodes = await WitOracleRadonRegistry.new( + radonRegistry = await WitOracleRadonRegistry.new( true, utils.fromAscii("testing") ) @@ -28,13 +29,12 @@ contract("WitOracleRadonRegistry", (accounts) => { context("Ownable2Step", async () => { it("should revert if transferring ownership from stranger", async () => { - await expectRevert( - bytecodes.transferOwnership(unprivilegedAddress, { from: unprivilegedAddress }), - "not the owner" + await expectRevert.unspecified( + radonRegistry.transferOwnership(unprivilegedAddress, { from: unprivilegedAddress }), ) }) it("owner can start transferring ownership", async () => { - const tx = await bytecodes.transferOwnership(firstOwnerAddress, { from: creatorAddress }) + const tx = await radonRegistry.transferOwnership(firstOwnerAddress, { from: creatorAddress }) expectEvent( tx.receipt, "OwnershipTransferStarted", @@ -43,12 +43,12 @@ contract("WitOracleRadonRegistry", (accounts) => { }) it("stranger cannot accept transferring ownership", async () => { await expectRevert( - bytecodes.acceptOwnership({ from: unprivilegedAddress }), + radonRegistry.acceptOwnership({ from: unprivilegedAddress }), "not the new owner" ) }) it("ownership is fully transferred upon acceptance", async () => { - const tx = await bytecodes.acceptOwnership({ from: firstOwnerAddress }) + const tx = await radonRegistry.acceptOwnership({ from: firstOwnerAddress }) expectEvent( tx.receipt, "OwnershipTransferred", @@ -57,33 +57,31 @@ contract("WitOracleRadonRegistry", (accounts) => { newOwner: firstOwnerAddress, } ) - assert.equal(firstOwnerAddress, await bytecodes.owner()) + assert.equal(firstOwnerAddress, await radonRegistry.owner()) }) }) context("Upgradeable", async () => { it("should manifest to be upgradable from actual owner", async () => { assert.equal( - await bytecodes.isUpgradableFrom(firstOwnerAddress), + await radonRegistry.isUpgradableFrom(firstOwnerAddress), true ) }) it("should manifest to not be upgradable from anybody else", async () => { assert.equal( - await bytecodes.isUpgradableFrom(unprivilegedAddress), + await radonRegistry.isUpgradableFrom(unprivilegedAddress), false ) }) it("cannot be initialized more than once", async () => { - await expectRevertCustomError( - WitOracleRadonRegistry, - bytecodes.initialize("0x", { from: firstOwnerAddress }), - "AlreadyUpgraded" + await expectRevert( + radonRegistry.initialize("0x", { from: firstOwnerAddress }), + "already initialized" ) - await expectRevertCustomError( - WitOracleRadonRegistry, - bytecodes.initialize("0x", { from: unprivilegedAddress }), - "OnlyOwner" + await expectRevert( + radonRegistry.initialize("0x", { from: unprivilegedAddress }), + "not the owner" ) }) }) @@ -108,29 +106,23 @@ contract("WitOracleRadonRegistry", (accounts) => { context("verifyRadonRetrieval(..)", async () => { context("Witnet.RadonRetrievalMethods.RNG", async () => { it("emits appropiate single event when verifying randomness data source for the first time", async () => { - const tx = await bytecodes.verifyRadonRetrieval( + const tx = await radonRegistry.verifyRadonRetrieval( 2, // requestMethod - "", // requestSchema - "", // requestFQDN - "", // requestPath - "", // requestQuery + "", // requestURL "", // requestBody [], // requestHeaders "0x80", // requestRadonScript ) expectEvent( tx.receipt, - "NewRadonRetrievalHash" + "NewRadonRetrieval" ) rngSourceHash = tx.logs[0].args.hash }) it("emits no event when verifying already existing randomness data source", async () => { - const tx = await bytecodes.verifyRadonRetrieval( + const tx = await radonRegistry.verifyRadonRetrieval( 2, // requestMethod - "", // requestSchema - "", // requestFQDN - "", // requestPath - "", // requestQuery + "", // requestURL "", // requestBody [], // requestHeaders "0x80", // requestRadonScript @@ -138,12 +130,9 @@ contract("WitOracleRadonRegistry", (accounts) => { assert.equal(tx.logs.length, 0, "some unexpected event was emitted") }) it("generates proper hash upon offchain verification of already existing randmoness source", async () => { - const hash = await bytecodes.verifyRadonRetrieval.call( + const hash = await radonRegistry.verifyRadonRetrieval.call( 2, // requestMethod - "", // requestSchema - "", // requestFQDN - "", // requestPath - "", // requestQuery + "", // requestURL "", // requestBody [], // requestHeaders "0x80", // requestRadonScript @@ -155,43 +144,37 @@ contract("WitOracleRadonRegistry", (accounts) => { context("Witnet.RadonRetrievalMethods.HttpGet", async () => { it( "emits new data provider and source events when verifying a new http-get source for the first time", async () => { - const tx = await bytecodes.verifyRadonRetrieval( + const tx = await radonRegistry.verifyRadonRetrieval( 1, // requestMethod - "HTTPs://", // requestSchema - "api.binance.US", // requestFQDN - "api/v3/ticker/price", // requestPath - "symbol=\\0\\\\1\\", // requestQuery + "https://api.binance.us/api/v3/ticker/price?symbol=\\0\\\\1\\", "", // requestBody [], // requestHeaders "0x841877821864696c61737450726963658218571a000f4240185b", // requestRadonScript ) + // expectEvent( + // tx.receipt, + // "NewDataProvider" + // ) + // assert.equal(tx.logs[0].args.index, 1) expectEvent( tx.receipt, - "NewDataProvider" - ) - assert.equal(tx.logs[0].args.index, 1) - expectEvent( - tx.receipt, - "NewRadonRetrievalHash" + "NewRadonRetrieval" ) - binanceTickerHash = tx.logs[1].args.hash + binanceTickerHash = tx.logs[0].args.hash }) it("data source metadata gets stored as expected", async () => { - const ds = await bytecodes.lookupRadonRetrieval(binanceTickerHash) + const ds = await radonRegistry.lookupRadonRetrieval(binanceTickerHash) assert.equal(ds.method, 1) // HTTP-GET - assert.equal(ds.resultDataType, 4) // Integer + assert.equal(ds.dataType, 4) // Integer assert.equal(ds.url, "https://api.binance.us/api/v3/ticker/price?symbol=\\0\\\\1\\") assert.equal(ds.body, "") assert(ds.headers.length === 0) - assert.equal(ds.script, "0x841877821864696c61737450726963658218571a000f4240185b") + assert.equal(ds.radonScript, "0x841877821864696c61737450726963658218571a000f4240185b") }) it("emits one single event when verifying new http-get endpoint to already existing provider", async () => { - const tx = await bytecodes.verifyRadonRetrieval( + const tx = await radonRegistry.verifyRadonRetrieval( 1, // requestMethod - "http://", // requestSchema - "api.binance.us", // requestFQDN - "api/v3/ticker/24hr", // requestPath - "symbol=\\0\\\\1\\", // requestQuery + "http://api.binance.us/api/v3/ticker/24hr?symbol=\\0\\\\1\\", // requestQuery "", // requestBody [], // requestHeaders "0x841877821864696c61737450726963658218571a000f4240185b", // requestRadonScript @@ -199,19 +182,16 @@ contract("WitOracleRadonRegistry", (accounts) => { assert.equal(tx.logs.length, 1) expectEvent( tx.receipt, - "NewRadonRetrievalHash" + "NewRadonRetrieval" ) }) }) context("Witnet.RadonRetrievalMethods.HttpPost", async () => { it( "emits new data provider and source events when verifying a new http-post source for the first time", async () => { - const tx = await bytecodes.verifyRadonRetrieval( + const tx = await radonRegistry.verifyRadonRetrieval( 3, // requestMethod - "HTTPs://", // requestSchema - "api.thegraph.com", // requestFQDN - "subgraphs/name/uniswap/uniswap-v3", // requestPath - "", // requestQuery + "https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v3", "{\"query\":\"{pool(id:\"\\0\\\"){token1Price}}\"}", // requestBody [ ["user-agent", "witnet-rust"], @@ -219,21 +199,21 @@ contract("WitOracleRadonRegistry", (accounts) => { ], // requestHeaders "0x861877821866646461746182186664706f6f6c8218646b746f6b656e3150726963658218571a000f4240185b", // requestRadonScript ) + // expectEvent( + // tx.receipt, + // "NewDataProvider" + // ) + // assert.equal(tx.logs[0].args.index, 2) expectEvent( tx.receipt, - "NewDataProvider" - ) - assert.equal(tx.logs[0].args.index, 2) - expectEvent( - tx.receipt, - "NewRadonRetrievalHash" + "NewRadonRetrieval" ) - uniswapToken1PriceHash = tx.logs[1].args.hash + uniswapToken1PriceHash = tx.logs[0].args.hash }) it("data source metadata gets stored as expected", async () => { - const ds = await bytecodes.lookupRadonRetrieval(uniswapToken1PriceHash) + const ds = await radonRegistry.lookupRadonRetrieval(uniswapToken1PriceHash) assert.equal(ds.method, 3) // HTTP-GET - assert.equal(ds.resultDataType, 4) // Integer + assert.equal(ds.dataType, 4) // Integer assert.equal(ds.url, "https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v3") assert.equal(ds.body, "{\"query\":\"{pool(id:\"\\0\\\"){token1Price}}\"}") assert(ds.headers.length === 2) @@ -241,30 +221,28 @@ contract("WitOracleRadonRegistry", (accounts) => { assert.equal(ds.headers[0][1], "witnet-rust") assert.equal(ds.headers[1][0], "content-type") assert.equal(ds.headers[1][1], "text/html; charset=utf-8") - assert.equal(ds.script, "0x861877821866646461746182186664706f6f6c8218646b746f6b656e3150726963658218571a000f4240185b") + assert.equal(ds.radonScript, "0x861877821866646461746182186664706f6f6c8218646b746f6b656e3150726963658218571a000f4240185b") }) }) }) context("verifyRadonReducer(..)", async () => { it("emits event when verifying new radon reducer with no filter", async () => { - const tx = await bytecodes.verifyRadonReducer([ + const tx = await radonRegistry.verifyRadonReducer([ 11, // opcode: ConcatenateAndHash [], // filters - "0x", // script ]) expectEvent( tx.receipt, - "NewRadonReducerHash" + "NewRadonReducer" ) concathashReducerHash = tx.logs[0].args.hash // concathashReducerBytecode = tx.logs[0].args.bytecode }) it("emits no event when verifying an already verified radon sla with no filter", async () => { - const tx = await bytecodes.verifyRadonReducer([ + const tx = await radonRegistry.verifyRadonReducer([ 11, // ConcatenateAndHash [], // filters - "0x", // script ]) assert.equal( tx.logs.length, @@ -273,70 +251,58 @@ contract("WitOracleRadonRegistry", (accounts) => { ) }) it("generates proper hash upon offchain call", async () => { - const hash = await bytecodes.verifyRadonReducer.call([ + const hash = await radonRegistry.verifyRadonReducer.call([ 11, // ConcatenateAndHash [], // filters - "0x", // script ]) assert.equal(hash, concathashReducerHash) }) - it("reverts custom error if verifying radon reducer with unsupported opcode", async () => { - await expectRevertCustomError( - Witnet, - bytecodes.verifyRadonReducer([ + it("reverts if verifying radon reducer with unsupported opcode", async () => { + await expectRevert.unspecified( + radonRegistry.verifyRadonReducer([ 0, // Minimum [], // filters - "0x", // script ]), - "UnsupportedRadonReducerOpcode" ) }) - it("reverts custom error if verifying radon reducer with at least one unsupported filter", async () => { - await expectRevertCustomError( - Witnet, - bytecodes.verifyRadonReducer([ + it("reverts if verifying radon reducer with at least one unsupported filter", async () => { + await expectRevert.unspecified( + radonRegistry.verifyRadonReducer([ 5, // AverageMedian [ [8, "0x"], // Mode: supported [0, "0x"], // Greater than: not yet supported ], - "0x", // script ]), - "UnsupportedRadonFilterOpcode" ) }) - it("reverts custom error if verifying radon reducer with stdev filter but no args", async () => { - await expectRevertCustomError( - Witnet, - bytecodes.verifyRadonReducer([ + it("reverts if verifying radon reducer with stdev filter but no args", async () => { + await expectRevert.unspecified( + radonRegistry.verifyRadonReducer([ 2, // Mode [ [5, "0x"], // Standard deviation filter ], - "0x", // script ]), - "RadonFilterMissingArgs" ) }) it("verifying radon reducer with stdev filter and args works", async () => { - let tx = await bytecodes.verifyRadonReducer([ + let tx = await radonRegistry.verifyRadonReducer([ 3, // AverageMean [ [5, "0xF93E00"], // StdDev(1.5) filter ], - "0x", // script ]) expectEvent( tx.receipt, - "NewRadonReducerHash" + "NewRadonReducer" ) stdev15ReducerHash = tx.logs[0].args.hash - tx = await bytecodes.verifyRadonReducer([ + tx = await radonRegistry.verifyRadonReducer([ 2, // Mode [ [5, "0xF94100"], // StdDev(2.5) filter ], - "0x", // script ]) stdev25ReducerHash = tx.logs[0].args.hash }) @@ -345,18 +311,17 @@ contract("WitOracleRadonRegistry", (accounts) => { context("verifyRadonRequest(..)", async () => { context("Use case: Randomness", async () => { it("emits single event when verifying new radomness request", async () => { - let tx = await bytecodes.verifyRadonReducer([ + let tx = await radonRegistry.verifyRadonReducer([ 2, // Mode [], // no filters - "0x", // script ]) expectEvent( tx.receipt, - "NewRadonReducerHash" + "NewRadonReducer" ) modeNoFiltersReducerHash = tx.logs[0].args.hash // modeNoFiltersReducerBytecode = tx.logs[0].args.bytecode - tx = await bytecodes.verifyRadonRequest( + tx = await radonRegistry.verifyRadonRequest( [ // sources rngSourceHash, ], @@ -367,12 +332,12 @@ contract("WitOracleRadonRegistry", (accounts) => { assert(tx.logs.length === 1) expectEvent( tx.receipt, - "NewRadHash" + "NewRadonRequest" ) - rngHash = tx.logs[0].args.hash + rngHash = tx.logs[0].args.radHash }) it("emits no event when verifying same randomness request", async () => { - const tx = await bytecodes.verifyRadonRequest( + const tx = await radonRegistry.verifyRadonRequest( [ // sources rngSourceHash, ], @@ -383,7 +348,7 @@ contract("WitOracleRadonRegistry", (accounts) => { assert(tx.logs.length === 0) }) it("generates same hash when verifying same randomness request offchain", async () => { - const hash = await bytecodes.verifyRadonRequest.call( + const hash = await radonRegistry.methods['verifyRadonRequest(bytes32[],bytes32,bytes32,uint16,string[][])'].call( [ // sources rngSourceHash, ], @@ -398,7 +363,7 @@ contract("WitOracleRadonRegistry", (accounts) => { context("Use case: Price feeds", async () => { it("reverts custom error if trying to verify request w/ templated source and 0 args out of 2", async () => { await expectRevert.unspecified( - bytecodes.verifyRadonRequest( + radonRegistry.verifyRadonRequest( [ // sources binanceTickerHash, ], @@ -411,7 +376,7 @@ contract("WitOracleRadonRegistry", (accounts) => { }) it("reverts custom error if trying to verify request w/ templated source and 1 args out of 2", async () => { await expectRevert.unspecified( - bytecodes.verifyRadonRequest( + radonRegistry.verifyRadonRequest( [ // sources binanceTickerHash, ], @@ -425,7 +390,7 @@ contract("WitOracleRadonRegistry", (accounts) => { ) }) it("emits single event when verifying new price feed request for the first time", async () => { - const tx = await bytecodes.verifyRadonRequest( + const tx = await radonRegistry.verifyRadonRequest( [ // source binanceTickerHash, ], @@ -439,13 +404,13 @@ contract("WitOracleRadonRegistry", (accounts) => { assert(tx.logs.length === 1) expectEvent( tx.receipt, - "NewRadHash" + "NewRadonRequest" ) - btcUsdPriceFeedHash = tx.logs[0].args.hash + btcUsdPriceFeedHash = tx.logs[0].args.radHash // btcUsdPriceFeedBytecode = tx.logs[0].args.bytecode }) it("verifying radon request with repeated sources works", async () => { - const tx = await bytecodes.verifyRadonRequest( + const tx = await radonRegistry.verifyRadonRequest( [ // sources binanceTickerHash, binanceTickerHash, @@ -461,13 +426,12 @@ contract("WitOracleRadonRegistry", (accounts) => { assert(tx.logs.length === 1) expectEvent( tx.receipt, - "NewRadHash" + "NewRadonRequest" ) }) it("reverts if trying to verify radon request w/ incompatible sources", async () => { - await expectRevertCustomError( - Witnet, - bytecodes.verifyRadonRequest( + await expectRevert( + radonRegistry.verifyRadonRequest( [ // sources binanceTickerHash, rngSourceHash, @@ -480,15 +444,11 @@ contract("WitOracleRadonRegistry", (accounts) => { [], ], ), - "RadonRequestResultsMismatch", [ - 1, // index - 0, // read - 4, // expected - ] + "mismatching retrievals" ) }) it("emits single event when verifying new radon request w/ http-post source", async () => { - const tx = await bytecodes.verifyRadonRequest( + const tx = await radonRegistry.verifyRadonRequest( [ // sources uniswapToken1PriceHash, ], @@ -502,11 +462,11 @@ contract("WitOracleRadonRegistry", (accounts) => { assert(tx.logs.length === 1) expectEvent( tx.receipt, - "NewRadHash" + "NewRadonRequest" ) }) it("emits single event when verifying new radon request w/ repeated http-post sources", async () => { - const tx = await bytecodes.verifyRadonRequest( + const tx = await radonRegistry.verifyRadonRequest( [ // sources uniswapToken1PriceHash, uniswapToken1PriceHash, @@ -530,192 +490,28 @@ contract("WitOracleRadonRegistry", (accounts) => { assert(tx.logs.length === 1) expectEvent( tx.receipt, - "NewRadHash" + "NewRadonRequest" ) - heavyRetrievalHash = tx.logs[0].args.hash + heavyRetrievalHash = tx.logs[0].args.radHash }) }) }) - context("verifyRadonSLA(..)", async () => { - it("emits event when verifying new radon sla", async () => { - const tx = await bytecodes.verifyRadonSLA([ - 10, - 51, - 10 ** 9, - 5 * 10 ** 9, - 10 ** 6, - ]) - expectEvent( - tx.receipt, - "NewSlaHash" - ) - slaHash = tx.logs[0].args.hash - }) - it("emits no event when verifying an already verified radon sla", async () => { - const tx = await bytecodes.verifyRadonSLA([ - 10, - 51, - 10 ** 9, - 5 * 10 ** 9, - 10 ** 6, - ]) - assert.equal( - tx.logs.length, - 0, - "some unexpected event was emitted" - ) - }) - it("generates proper hash upon offchain call", async () => { - const hash = await bytecodes.verifyRadonSLA.call([ - 10, - 51, - 10 ** 9, - 5 * 10 ** 9, - 10 ** 6, - ]) - assert.equal(hash, slaHash) - }) - it("reverts custom error if verifying radon sla with no reward", async () => { - await expectRevertCustomError( - Witnet, - bytecodes.verifyRadonSLA([ - 10, - 51, - 0, - 5 * 10 ** 9, - 10 ** 6, - ]), - "RadonSlaNoReward" - ) - }) - it("reverts custom error if verifying radon sla with no witnesses", async () => { - await expectRevertCustomError( - Witnet, - bytecodes.verifyRadonSLA([ - 0, - 51, - 10 ** 9, - 5 * 10 ** 9, - 10 ** 6, - ]), - "RadonSlaNoWitnesses" - ) - }) - it("reverts custom error if verifying radon sla with too many witnesses", async () => { - await expectRevertCustomError( - Witnet, - bytecodes.verifyRadonSLA([ - 500, - 51, - 10 ** 9, - 15 * 10 ** 9, - 10 ** 6, - ]), - "RadonSlaTooManyWitnesses" - ) - }) - it("reverts custom error if verifying radon sla with quorum out of range", async () => { - await expectRevertCustomError( - Witnet, - bytecodes.verifyRadonSLA([ - 10, - 50, - 10 ** 9, - 15 * 10 ** 9, - 10 ** 6, - ]), - "RadonSlaConsensusOutOfRange" - ) - await expectRevertCustomError( - Witnet, - bytecodes.verifyRadonSLA([ - 10, - 100, - 10 ** 9, - 5 * 10 ** 9, - 10 ** 6, - ]), - "RadonSlaConsensusOutOfRange" - ) - }) - it("reverts custom error if verifying radon sla with too low collateral", async () => { - await expectRevertCustomError( - Witnet, - bytecodes.verifyRadonSLA([ - 10, - 51, - 10 ** 6, - 10 ** 6, - 10 ** 6, - ]), - "RadonSlaLowCollateral" - ) - }) - }) - context("bytecodeOf(..)", async () => { context("radon requests", async () => { it("reverts if trying to get bytecode from unknown radon request", async () => { - await expectRevertCustomError( - WitOracleRadonRegistry, - bytecodes.bytecodeOf("0x0"), - "UnknownRadonRequest" + await expectRevert( + radonRegistry.bytecodeOf("0x0"), + "unverified" ) }) it("works if trying to get bytecode onchain from known radon request", async () => { - await bytecodes.bytecodeOf(btcUsdPriceFeedHash) + await radonRegistry.bytecodeOf(btcUsdPriceFeedHash) }) it("returns bytecode if getting it offchain from known radon request", async () => { - await bytecodes.bytecodeOf(btcUsdPriceFeedHash) + await radonRegistry.bytecodeOf(btcUsdPriceFeedHash) }) }) - context("radon slas", async () => { - it("reverts if trying to get bytecode from unknown radon sla", async () => { - await expectRevertCustomError( - WitOracleRadonRegistry, - bytecodes.bytecodeOf(btcUsdPriceFeedHash, "0x0"), - "UnknownRadonSLA" - ) - }) - it("works if trying to get bytecode onchain from known radon request and sla", async () => { - await bytecodes.bytecodeOf(btcUsdPriceFeedHash, slaHash) - }) - }) - }) - - context("hashOf(..)", async () => { - it("hashing unknown radon request doesn't revert", async () => { - await bytecodes.hashOf("0x", slaHash) - }) - it("hashing unknown radon sla doesn't revert", async () => { - await bytecodes.hashOf(btcUsdPriceFeedHash, "0x0") - }) - it("hashing of known radon request and sla works", async () => { - await bytecodes.hashOf(btcUsdPriceFeedHash, slaHash) - }) - }) - - context("hashWeightRewardOf(..)", async () => { - it("hashing unknown radon request reverts", async () => { - await expectRevertCustomError( - WitOracleRadonRegistry, - bytecodes.hashWeightWitsOf("0x0", slaHash), - "UnknownRadonRequest" - ) - }) - it("hashing unknown radon sla reverts", async () => { - await expectRevertCustomError( - WitOracleRadonRegistry, - bytecodes.hashWeightWitsOf(btcUsdPriceFeedHash, "0x0"), - "UnknownRadonSLA" - ) - }) - it("hashing of known radon request and sla works", async () => { - await bytecodes.hashWeightWitsOf( - heavyRetrievalHash, slaHash - ) - }) }) }) })