Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added README.md
Empty file.
48 changes: 48 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -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'
5 changes: 0 additions & 5 deletions migrations/1_initial_migration.js

This file was deleted.

4 changes: 0 additions & 4 deletions migrations/2_test.js

This file was deleted.

4 changes: 0 additions & 4 deletions migrations/3_port_token_migrattion.js

This file was deleted.

4 changes: 0 additions & 4 deletions migrations/4_access_migration.js

This file was deleted.

20 changes: 0 additions & 20 deletions migrations/5_offChain_aggregator.js

This file was deleted.

11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
71 changes: 64 additions & 7 deletions test/offChainAggregator.js
Original file line number Diff line number Diff line change
@@ -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];
Expand Down Expand Up @@ -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]);
Expand All @@ -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];
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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");
Expand Down
18 changes: 9 additions & 9 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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",
Expand All @@ -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");
Expand All @@ -61,15 +61,15 @@ 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();
//console.log(gasPrice.toString());
});

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");
Expand All @@ -87,15 +87,15 @@ 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");
assert.equal(decodeData._observerCount, "0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", "invalid _observerCount");
});

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");
Expand All @@ -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";
Expand All @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion truffle-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down