diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000..1618dd2 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,48 @@ +jobs: + # All tasks on Windows.... + - job: build_all_windows + displayName: Build all tasks (Windows) + timeoutInMinutes: 120 + pool: + vmImage: windows-latest + steps: + - task: Npm@1 + inputs: + command: 'install' + displayName: npm install + - script: npx truffle test + displayName: 'test' + + # All tasks on Linux + - job: build_all_linux + displayName: Build all tasks (Linux) + timeoutInMinutes: 120 + pool: + vmImage: ubuntu-latest + steps: + - task: Npm@1 + inputs: + command: 'install' + displayName: npm install + # - script: npm install --save-dev solidity-coverage@beta + # displayName: 'install solidity-coverage' + - script: npx truffle run coverage + displayName: 'test' + - script: | + curl -Os https://uploader.codecov.io/latest/linux/codecov + chmod +x codecov + ./codecov -t $CODECOV_TOKEN + displayName: 'upload to codecov' + # All tasks on macOS + - job: build_all_darwin + displayName: Build all tasks (macOS) + timeoutInMinutes: 120 + pool: + vmImage: macos-latest + steps: + - task: Npm@1 + inputs: + command: 'install' + displayName: npm install + - script: npx truffle test + displayName: 'test' \ No newline at end of file diff --git a/migrations/1_initial_migration.js b/migrations/1_initial_migration.js deleted file mode 100644 index 16a7ba5..0000000 --- a/migrations/1_initial_migration.js +++ /dev/null @@ -1,5 +0,0 @@ -const Migrations = artifacts.require("Migrations"); - -module.exports = function (deployer) { - deployer.deploy(Migrations); -}; diff --git a/migrations/2_test.js b/migrations/2_test.js deleted file mode 100644 index 55ceddf..0000000 --- a/migrations/2_test.js +++ /dev/null @@ -1,4 +0,0 @@ -const TestContract = artifacts.require("Test"); -module.exports = function (deployer) { - deployer.deploy(TestContract); -}; diff --git a/migrations/3_port_token_migrattion.js b/migrations/3_port_token_migrattion.js deleted file mode 100644 index 02d4689..0000000 --- a/migrations/3_port_token_migrattion.js +++ /dev/null @@ -1,4 +0,0 @@ -const PortContract = artifacts.require("MockPortToken"); -module.exports = function (deployer) { - deployer.deploy(PortContract); -}; diff --git a/migrations/4_access_migration.js b/migrations/4_access_migration.js deleted file mode 100644 index 9430073..0000000 --- a/migrations/4_access_migration.js +++ /dev/null @@ -1,4 +0,0 @@ -const AccessContract = artifacts.require("SimpleWriteAccessController"); -module.exports = function (deployer) { - deployer.deploy(AccessContract); -}; diff --git a/migrations/5_offChain_aggregator.js b/migrations/5_offChain_aggregator.js deleted file mode 100644 index 144f72b..0000000 --- a/migrations/5_offChain_aggregator.js +++ /dev/null @@ -1,20 +0,0 @@ -const AccessContract = artifacts.require("SimpleWriteAccessController"); -const PortContract = artifacts.require("MockPortToken"); -const OffChainAggregator = artifacts.require("AccessControlledOffchainAggregator"); -module.exports = function (deployer) { - - - let maximumGasPrice = 1; - let reasonableGasPrice = 10; - let microPortPerEth = 1000000; - let portGweiPerObservation = 500; - let portGweiPerTransmission = 300; - let port = PortContract.address; - let billingAccessController = AccessContract.address; - let requesterAccessController = AccessContract.address; - let decimals = 8; - let description = "query something"; - - deployer.deploy(OffChainAggregator, maximumGasPrice, reasonableGasPrice, microPortPerEth, portGweiPerObservation, portGweiPerTransmission, - port, billingAccessController, requesterAccessController, decimals, description); -}; diff --git a/package.json b/package.json index ddd8af7..41d56fd 100644 --- a/package.json +++ b/package.json @@ -4,11 +4,16 @@ "dotenv": "^9.0.2", "readline-sync": "^1.4.10", "solc": "^0.8.3", + "truffle-contract-size": "^2.0.1", "truffle-hdwallet-provider": "^1.0.17", "truffle-hdwallet-provider-privkey": "^0.3.0", - "web3": "^1.3.4" + "web3": "^1.3.4", + "ganache": "^7.1.0", + "truffle": "5.5.28" }, "devDependencies": { - "prettier": "2.2.1" + "prettier": "2.2.1", + "truffle-plugin-verify": "^0.5.7", + "solidity-coverage": "0.8.0-beta.1" } -} +} \ No newline at end of file diff --git a/test/offChainAggregator.js b/test/offChainAggregator.js index f41dd62..5726b39 100644 --- a/test/offChainAggregator.js +++ b/test/offChainAggregator.js @@ -1,10 +1,25 @@ const testContract = artifacts.require("AccessControlledOffchainAggregator"); const PortContract = artifacts.require("MockPortToken"); +const AccessContract = artifacts.require("SimpleWriteAccessController"); contract('master chef', (accounts) => { it('single one observation with byte length less than 32', async () => { - const testInstance = await testContract.deployed(); - const portTokenInstance = await PortContract.deployed(); + const portTokenInstance = await PortContract.new(); + const AccessInstance = await AccessContract.new(); + let maximumGasPrice = 1; + let reasonableGasPrice = 10; + let microPortPerEth = 1000000; + let portGweiPerObservation = 500; + let portGweiPerTransmission = 300; + let port = portTokenInstance.address; + let billingAccessController = AccessInstance.address; + let requesterAccessController = AccessInstance.address; + let decimals = 8; + let description = "query something"; + + const testInstance = await testContract.new(maximumGasPrice, reasonableGasPrice, microPortPerEth, portGweiPerObservation, portGweiPerTransmission, + port, billingAccessController, requesterAccessController, decimals, description); + let transmitterOne = accounts[0]; let payeeOne = accounts[1]; let transmitterTwo = accounts[3]; @@ -32,9 +47,10 @@ contract('master chef', (accounts) => { await testInstance.setPayees(transmiters, payees); await testInstance.setConfig(signers, transmiters, configVersion, encoded); let config = await testInstance.latestConfigDetails(); - //console.log(config.configDigest); + console.log("digest:"+config.configDigest); let report = "0x000000000000f6f3ed664fd0e7be332f035ec351acf1000000000000000a02050001020000000000000000000000000000000000000000000000000000000000000102000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000000161736461730000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; + let rs = [signerOneR, signerTwoR]; let ss = [signerOneS, signerTwoS]; let vs = web3.utils.bytesToHex([signerOneV, signerTwoV, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0]); @@ -57,7 +73,21 @@ contract('master chef', (accounts) => { }); it('multiple observations with answer length less than 32', async () => { - const testInstance = await testContract.deployed(); + const portTokenInstance = await PortContract.new(); + const AccessInstance = await AccessContract.new(); + let maximumGasPrice = 1; + let reasonableGasPrice = 10; + let microPortPerEth = 1000000; + let portGweiPerObservation = 500; + let portGweiPerTransmission = 300; + let port = portTokenInstance.address; + let billingAccessController = AccessInstance.address; + let requesterAccessController = AccessInstance.address; + let decimals = 8; + let description = "query something"; + + const testInstance = await testContract.new(maximumGasPrice, reasonableGasPrice, microPortPerEth, portGweiPerObservation, portGweiPerTransmission, + port, billingAccessController, requesterAccessController, decimals, description); let transmitterOne = accounts[0]; let payeeOne = accounts[1]; let transmitterTwo = accounts[3]; @@ -114,7 +144,21 @@ contract('master chef', (accounts) => { }); it('multiple observations with answer length greater than 32', async () => { - const testInstance = await testContract.deployed(); + const portTokenInstance = await PortContract.new(); + const AccessInstance = await AccessContract.new(); + let maximumGasPrice = 1; + let reasonableGasPrice = 10; + let microPortPerEth = 1000000; + let portGweiPerObservation = 500; + let portGweiPerTransmission = 300; + let port = portTokenInstance.address; + let billingAccessController = AccessInstance.address; + let requesterAccessController = AccessInstance.address; + let decimals = 8; + let description = "query something"; + + const testInstance = await testContract.new(maximumGasPrice, reasonableGasPrice, microPortPerEth, portGweiPerObservation, portGweiPerTransmission, + port, billingAccessController, requesterAccessController, decimals, description); let signerOneAddress = "0x824b3998700F7dcB7100D484c62a7b472B6894B6"; // generated on aelf //let signerOnePrivateKey = "7f6965ae260469425ae839f5abc85b504883022140d5f6fc9664a96d480c068d"; @@ -156,8 +200,21 @@ contract('master chef', (accounts) => { }); it('configuration test', async () => { - const testInstance = await testContract.deployed(); - const portTokenInstance = await PortContract.deployed(); + const portTokenInstance = await PortContract.new(); + const AccessInstance = await AccessContract.new(); + let maximumGasPrice = 1; + let reasonableGasPrice = 10; + let microPortPerEth = 1000000; + let portGweiPerObservation = 500; + let portGweiPerTransmission = 300; + let port = portTokenInstance.address; + let billingAccessController = AccessInstance.address; + let requesterAccessController = AccessInstance.address; + let decimals = 8; + let description = "query something"; + + const testInstance = await testContract.new(maximumGasPrice, reasonableGasPrice, microPortPerEth, portGweiPerObservation, portGweiPerTransmission, + port, billingAccessController, requesterAccessController, decimals, description); await testInstance.requestNewRound(); let requestNewRoundEvent = (await testInstance.getPastEvents('RoundRequested'))[0].returnValues; assert.equal(requestNewRoundEvent.requester, accounts[0], "invalid requester info"); diff --git a/test/test.js b/test/test.js index 1a1c994..8102c21 100644 --- a/test/test.js +++ b/test/test.js @@ -2,7 +2,7 @@ const MyTest = artifacts.require("Test"); contract('MyTest', (accounts) => { it('code test', async () => { - const testInstance = await MyTest.deployed(); + const testInstance = await MyTest.new(); await testInstance.generateBytes32("0x123456789abcd"); let a = await testInstance.bytes32v(); let b = await testInstance.decodeBytes32(a); @@ -28,7 +28,7 @@ contract('MyTest', (accounts) => { }); it('sha test', async () => { - const testInstance = await MyTest.deployed(); + const testInstance = await MyTest.new(); let context = "0x0000000000000000000000070707070707070707070707070707070000001010"; let observers = "0x0001020304000000000000000000000000000000000000000000000000000000"; let dataList = ["0x000000000000000000000000000000000000000000000000000000000000007b", @@ -44,7 +44,7 @@ contract('MyTest', (accounts) => { }); it('decode report', async () => { - const testInstance = await MyTest.deployed(); + const testInstance = await MyTest.new(); let encodeData = "0x00000000000007070707070707070707070707070707000000000000000a030700040a00000000000000000000000000000000000000000000000000000000000a05617364617300000000000000000000000000000000000000000000000000"; let decodeData = await testInstance.decodeReport2(encodeData); assert.equal(decodeData.roundId, 10, "invalid round id"); @@ -61,7 +61,7 @@ contract('MyTest', (accounts) => { }); it('fee test', async () => { - const testInstance = await MyTest.deployed(); + const testInstance = await MyTest.new(); let gweiAmount = await testInstance.getGweiAmount(); assert.equal(gweiAmount.toString(), 1000000000); let gasPrice = await testInstance.getGasPrice(); @@ -69,7 +69,7 @@ contract('MyTest', (accounts) => { }); it('decode 4 with multple observations test', async () => { - const testInstance = await MyTest.deployed(); + const testInstance = await MyTest.new(); let encodeData = "0x000000000000f6f3ed664fd0e7be332f035ec351acf1000000000000000a0307000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e00000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e000a056173646173000000000000000000000000000000000000000000000000000001020000000000000000000000000000000000000000000000000000000000060606000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000030a0431203a3400000000000000000000000000000000000000000000000000000a0431203a3500000000000000000000000000000000000000000000000000000a0431203a360000000000000000000000000000000000000000000000000000"; let decodeData = await testInstance.decodeReport4(encodeData); assert.equal(decodeData._observerOrder.length, 3, "invalid _observerOrder"); @@ -87,7 +87,7 @@ contract('MyTest', (accounts) => { }); it('decode 4 with multple observations test2', async () => { - const testInstance = await MyTest.deployed(); + const testInstance = await MyTest.new(); let encodeData = "0x00000000000022d6f8928689ea183a3eb24df3919a94000000000000000b0320000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a080001020000000000000000000000000000000000000000000000000000000000060606000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000030a0431203a3400000000000000000000000000000000000000000000000000000a0431203a3500000000000000000000000000000000000000000000000000000a0431203a360000000000000000000000000000000000000000000000000000"; let decodeData = await testInstance.decodeReport4(encodeData); assert.equal(decodeData._count.toString(), 3, "invalid count"); @@ -95,7 +95,7 @@ contract('MyTest', (accounts) => { }); it('decode 4 with single observation test', async () => { - const testInstance = await MyTest.deployed(); + const testInstance = await MyTest.new(); let encodeData = "0x000000000000f6f3ed664fd0e7be332f035ec351acf1000000000000000a0007000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e00000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e000a056173646173000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000000"; let decodeData = await testInstance.decodeReport4(encodeData); assert.equal(decodeData._observerOrder.length, 0, "invalid _observerOrder"); @@ -106,7 +106,7 @@ contract('MyTest', (accounts) => { }); it('sign verification', async () => { - const testInstance = await MyTest.deployed(); + const testInstance = await MyTest.new(); let report = "0x000000000000f6f3ed664fd0e7be332f035ec351acf1000000000000000a0007000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f0a056173646173000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000000"; let address = "0x824b3998700F7dcB7100D484c62a7b472B6894B6"; let privateKey = "7f6965ae260469425ae839f5abc85b504883022140d5f6fc9664a96d480c068d"; @@ -119,7 +119,7 @@ contract('MyTest', (accounts) => { }); it('test bytes copy', async () => { - const testInstance = await MyTest.deployed(); + const testInstance = await MyTest.new(); let a = await testInstance.getString("lw", 2); assert.equal(a, "lw", "invalid get string"); diff --git a/truffle-config.js b/truffle-config.js index 55c1f79..91a7403 100644 --- a/truffle-config.js +++ b/truffle-config.js @@ -102,7 +102,7 @@ module.exports = { } }, plugins: [ - 'truffle-plugin-verify', 'truffle-contract-size' + 'truffle-plugin-verify', 'truffle-contract-size','solidity-coverage' ], // api_keys: { // etherscan: process.parsed.ETHERSCAN_API_KEY