Skip to content

Commit

Permalink
test multiple val update
Browse files Browse the repository at this point in the history
  • Loading branch information
tkernell committed Dec 15, 2023
1 parent 4877fff commit fe26138
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 16 deletions.

This file was deleted.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../build-info/370f2fab6b7421a376776c833987ed27.json"
"buildInfo": "../../../build-info/f76c78aba5d18f1bb85220221f9b7f86.json"
}
10 changes: 8 additions & 2 deletions evm/artifacts/contracts/bridge/BlobstreamO.sol/BlobstreamO.json

Large diffs are not rendered by default.

36 changes: 34 additions & 2 deletions evm/cache/solidity-files-cache.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"_format": "hh-sol-cache-2",
"files": {
"/Users/timothykernell/Documents/tellor/cosmos/layer/evm/contracts/bridge/BlobstreamO.sol": {
"lastModificationDate": 1702648212227,
"contentHash": "7ee9ed20e9bbc527f9a0dca40e2600ac",
"lastModificationDate": 1702653443025,
"contentHash": "8af08dce1bd341875bd2653c11586fc3",
"sourceName": "contracts/bridge/BlobstreamO.sol",
"solcConfig": {
"version": "0.8.22",
Expand Down Expand Up @@ -258,6 +258,38 @@
"artifacts": [
"console"
]
},
"/Users/timothykernell/Documents/tellor/cosmos/layer/evm/contracts/usingtellor/UsingTellor.sol": {
"lastModificationDate": 1702653628959,
"contentHash": "d41d8cd98f00b204e9800998ecf8427e",
"sourceName": "contracts/usingtellor/UsingTellor.sol",
"solcConfig": {
"version": "0.8.22",
"settings": {
"evmVersion": "paris",
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"abi",
"evm.bytecode",
"evm.deployedBytecode",
"evm.methodIdentifiers",
"metadata"
],
"": [
"ast"
]
}
}
}
},
"imports": [],
"versionPragmas": [],
"artifacts": []
}
}
}
5 changes: 4 additions & 1 deletion evm/contracts/bridge/BlobstreamO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ contract BlobstreamO is ECDSA {
event ValidatorSetUpdated(
uint256 indexed _nonce,
uint256 _powerThreshold,
uint256 _validatorTimestamp,
bytes32 _validatorSetHash
);

Expand Down Expand Up @@ -138,7 +139,7 @@ contract BlobstreamO is ECDSA {
}

bytes32 _newCheckpoint = _domainSeparateValidatorSetHash(
validatorNonce,
validatorNonce + 1,
_newPowerThreshold,
_newValidatorTimestamp,
_newValidatorSetHash
Expand All @@ -151,10 +152,12 @@ contract BlobstreamO is ECDSA {
);
lastValidatorSetCheckpoint = _newCheckpoint;
powerThreshold = _newPowerThreshold;
validatorTimestamp = _newValidatorTimestamp;
validatorNonce++;
emit ValidatorSetUpdated(
validatorNonce,
_newPowerThreshold,
_newValidatorTimestamp,
_newValidatorSetHash
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,28 @@ describe("BlobstreamO - Function Tests Manual", function () {
});

it("constructor", async function () {

assert.equal(await bridge.validatorNonce(), nonce)
assert.equal(await bridge.powerThreshold(), threshold)
assert.equal(await bridge.validatorTimestamp(), valTimestamp)
assert.equal(await bridge.unbondingPeriod(), UNBONDING_PERIOD)
assert.equal(await bridge.lastValidatorSetCheckpoint(), valCheckpoint)
})

it("updateValidatorSet", async function() {
newValAddrs = [accounts[1].address, accounts[2].address, accounts[3].address]
newPowers = [1, 2, 3]
newThreshold = 4
newValHash = await h.calculateValHash(newValAddrs, newPowers)
newNonce = nonce + 1
blocky = await h.getBlock()
newValTimestamp = blocky.timestamp - 1
newValCheckpoint = h.calculateValCheckpoint(newValAddrs, newPowers, nonce, newThreshold, newValTimestamp)
newValCheckpoint = h.calculateValCheckpoint(newValAddrs, newPowers, newNonce, newThreshold, newValTimestamp)
newDigest = await h.getEthSignedMessageHash(newValCheckpoint)
valSetArray = await h.getValSetStructArray(initialValAddrs, initialPowers)
currentValSetArray = await h.getValSetStructArray(initialValAddrs, initialPowers)
sig1 = await accounts[1].signMessage(ethers.utils.arrayify(newValCheckpoint))
sig2 = await accounts[2].signMessage(ethers.utils.arrayify(newValCheckpoint))
sigStructArray = await h.getSigStructArray([sig1, sig2])
await bridge.updateValidatorSet(newValHash, newThreshold, newValTimestamp, valSetArray, sigStructArray);


await bridge.updateValidatorSet(newValHash, newThreshold, newValTimestamp, currentValSetArray, sigStructArray);
})

it("verifyOracleData", async function() {
Expand All @@ -70,7 +73,7 @@ describe("BlobstreamO - Function Tests Manual", function () {
blockTimestamp
)

valSetArray = await h.getValSetStructArray(initialValAddrs, initialPowers)
currentValSetArray = await h.getValSetStructArray(initialValAddrs, initialPowers)
sig1 = await accounts[1].signMessage(ethers.utils.arrayify(dataDigest))
sig2 = await accounts[2].signMessage(ethers.utils.arrayify(dataDigest))
sigStructArray = await h.getSigStructArray([sig1, sig2])
Expand All @@ -87,9 +90,42 @@ describe("BlobstreamO - Function Tests Manual", function () {

await bridge.verifyOracleData(
oracleDataStruct,
valSetArray,
currentValSetArray,
sigStructArray
)
})


it("updateValidatorSet twice", async function() {
newValAddrs = [accounts[1].address, accounts[2].address, accounts[3].address]
newPowers = [1, 2, 3]
newThreshold = 4
newValHash = await h.calculateValHash(newValAddrs, newPowers)
newNonce = nonce + 1
blocky = await h.getBlock()
newValTimestamp = blocky.timestamp - 1
newValCheckpoint = h.calculateValCheckpoint(newValAddrs, newPowers, newNonce, newThreshold, newValTimestamp)
console.log("newValCheckpoint", newValCheckpoint)
newDigest = await h.getEthSignedMessageHash(newValCheckpoint)
currentValSetArray = await h.getValSetStructArray(initialValAddrs, initialPowers)
sig1 = await accounts[1].signMessage(ethers.utils.arrayify(newValCheckpoint))
sig2 = await accounts[2].signMessage(ethers.utils.arrayify(newValCheckpoint))
sigStructArray = await h.getSigStructArray([sig1, sig2])
await bridge.updateValidatorSet(newValHash, newThreshold, newValTimestamp, currentValSetArray, sigStructArray);

newValAddrs2 = [accounts[4].address, accounts[5].address, accounts[6].address, accounts[7].address]
newPowers2 = [4, 5, 6, 7]
newThreshold2 = 15
newValHash2 = await h.calculateValHash(newValAddrs2, newPowers2)
newNonce2 = newNonce + 1
blocky = await h.getBlock()
newValTimestamp2 = blocky.timestamp - 1
newValCheckpoint2 = h.calculateValCheckpoint(newValAddrs2, newPowers2, newNonce2, newThreshold2, newValTimestamp2)
newDigest2 = await h.getEthSignedMessageHash(newValCheckpoint2)
currentValSetArray2 = await h.getValSetStructArray(newValAddrs, newPowers)
sig1 = await accounts[1].signMessage(ethers.utils.arrayify(newValCheckpoint2))
sig2 = await accounts[2].signMessage(ethers.utils.arrayify(newValCheckpoint2))
sig3 = await accounts[3].signMessage(ethers.utils.arrayify(newValCheckpoint2))
sigStructArray2 = await h.getSigStructArray([sig1, sig2, sig3])
await bridge.updateValidatorSet(newValHash2, newThreshold2, newValTimestamp2, currentValSetArray2, sigStructArray2);
})
})

0 comments on commit fe26138

Please sign in to comment.