-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve beefy tests #901
Merged
Merged
Improve beefy tests #901
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8bfa91b
Improve Beefy tests
yrong 33a74cf
Merge branch 'proxy-contracts' into ron/improve-beefy-tests
yrong f22ebe4
Merge branch 'proxy-contracts' into ron/improve-beefy-tests
yrong bae41ff
Update gas snapshot
yrong 165875d
Split test fixture
yrong 577ed4a
Update snapshot
yrong 196330a
Decode mmr leaf from commitment file
yrong 06e3668
Regenerate final bitField
yrong e82ca88
Update foundry remove ffi
yrong abe1811
Update test remove hardcode check
yrong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,70 @@ | ||
BeefyClientTest:testScaleEncodeCommit() (gas: 32228) | ||
BeefyClientTest:testSubmit() (gas: 640426) | ||
BeefyClientTest:testSubmitFailForPrevRandaoCapturedMoreThanOnce() (gas: 269498) | ||
BeefyClientTest:testSubmitFailForPrevRandaoTooEarlyOrTooLate() (gas: 210184) | ||
BeefyClientTest:testSubmitFailInvalidSignature() (gas: 581588) | ||
BeefyClientTest:testSubmitFailValidatorNotInBitfield() (gas: 568657) | ||
BeefyClientTest:testSubmitFailWithInvalidBitfield() (gas: 559304) | ||
BeefyClientTest:testSubmitFailWithStaleCommitment() (gas: 757824) | ||
BeefyClientTest:testSubmitFailWithoutPrevRandao() (gas: 535343) | ||
BeefyClientTest:testSubmitWithHandover() (gas: 668392) | ||
BeefyClientTest:testSubmitWithHandoverFailStaleCommitment() (gas: 781735) | ||
BeefyClientTest:testSubmitWithHandoverFailWithoutPrevRandao() (gas: 559560) | ||
InboundQueueTest:testSubmit() (gas: 117979) | ||
InboundQueueTest:testSubmitShouldFailInsufficientBalance() (gas: 92436) | ||
InboundQueueTest:testSubmitShouldFailInvalidNonce() (gas: 66955) | ||
InboundQueueTest:testSubmitShouldFailInvalidProof() (gas: 62637) | ||
InboundQueueTest:testSubmitShouldNotFailOnHandlerFailure() (gas: 142351) | ||
InboundQueueTest:testSubmitShouldNotFailOnHandlerOOG() (gas: 641523) | ||
NativeTokensTest:testCreateFailOnBadFeePayment() (gas: 11593) | ||
NativeTokensTest:testCreateFailOnBadToken() (gas: 19174) | ||
NativeTokensTest:testCreateSuccessful() (gas: 79603) | ||
NativeTokensTest:testHandleRevertsUnknownOrigin() (gas: 12280) | ||
NativeTokensTest:testHandleRevertsUnknownSender() (gas: 44241) | ||
NativeTokensTest:testHandleUnlockMessageSuccessful() (gas: 154612) | ||
NativeTokensTest:testLockRevertsZeroAmount() (gas: 11361) | ||
NativeTokensTest:testLockSuccessful() (gas: 161012) | ||
OutboundQueueTest:testSubmit() (gas: 82052) | ||
OutboundQueueTest:testSubmitFailFeePaymentTooLow() (gas: 30057) | ||
ParachainClientTest:testCreateParachainHeaderMerkleFailInvalidHeader() (gas: 12690) | ||
ParachainClientTest:testCreateParachainHeaderMerkleLeaf() (gas: 23474) | ||
ParachainClientTest:testIsCommitmentInHeaderDigest() (gas: 23454) | ||
ScaleCodecTest:testEncodeU128() (gas: 193) | ||
ScaleCodecTest:testEncodeU16() (gas: 414) | ||
ScaleCodecTest:testEncodeU256() (gas: 453) | ||
ScaleCodecTest:testEncodeU32() (gas: 171) | ||
ScaleCodecTest:testEncodeU64() (gas: 281) | ||
TokenVaultTest:testDepositSuccessful() (gas: 106091) | ||
TokenVaultTest:testInsufficientBalance() (gas: 17425) | ||
TokenVaultTest:testNonOwnerCannotWithdraw() (gas: 44613) | ||
TokenVaultTest:testTokenTransferFailedInsufficientAllowance() (gas: 69957) | ||
TokenVaultTest:testWithdrawSuccessful() (gas: 121381) | ||
UpgradeProxyTest:testUpgrade() (gas: 35658) | ||
UpgradeProxyTest:testUpgradeFail() (gas: 20802) | ||
UpgradeProxyTest:testUpgradeFailBadOrigin() (gas: 11326) | ||
AgentTest:testInvoke() (gas: 20810) | ||
AgentTest:testInvokeFail() (gas: 13429) | ||
AgentTest:testInvokeUnauthorized() (gas: 13974) | ||
BeefyClientTest:testCreateFinalBitfield() (gas: 278225) | ||
BeefyClientTest:testCreateFinalBitfieldInvalid() (gas: 265008) | ||
BeefyClientTest:testCreateInitialBitfield() (gas: 650507) | ||
BeefyClientTest:testCreateInitialBitfieldInvalid() (gas: 578841) | ||
BeefyClientTest:testScaleEncodeCommit() (gas: 32353) | ||
BeefyClientTest:testSubmit():((uint32,uint64,(bytes2,bytes)[])) (gas: 708627) | ||
BeefyClientTest:testSubmitFailForPrevRandaoCapturedMoreThanOnce() (gas: 266184) | ||
BeefyClientTest:testSubmitFailForPrevRandaoTooEarlyOrTooLate() (gas: 207388) | ||
BeefyClientTest:testSubmitFailInvalidSignature() (gas: 657123) | ||
BeefyClientTest:testSubmitFailValidatorNotInBitfield() (gas: 645077) | ||
BeefyClientTest:testSubmitFailWithInvalidBitfield() (gas: 634383) | ||
BeefyClientTest:testSubmitFailWithInvalidMMRLeaf() (gas: 748779) | ||
BeefyClientTest:testSubmitFailWithInvalidMMRLeafProof() (gas: 752764) | ||
BeefyClientTest:testSubmitFailWithInvalidTicket() (gas: 638107) | ||
BeefyClientTest:testSubmitFailWithInvalidValidatorSet() (gas: 642432) | ||
BeefyClientTest:testSubmitFailWithNotEnoughClaims() (gas: 197586) | ||
BeefyClientTest:testSubmitFailWithStaleCommitment() (gas: 835952) | ||
BeefyClientTest:testSubmitFailWithoutPrevRandao() (gas: 532261) | ||
BeefyClientTest:testSubmitWithHandover() (gas: 736139) | ||
BeefyClientTest:testSubmitWithHandoverFailStaleCommitment() (gas: 859922) | ||
BeefyClientTest:testSubmitWithHandoverFailWithInvalidValidatorSet() (gas: 666242) | ||
BeefyClientTest:testSubmitWithHandoverFailWithoutPrevRandao() (gas: 556301) | ||
GatewayTest:testAgentExecution() (gas: 52791) | ||
GatewayTest:testAgentExecutionBadOrigin() (gas: 23354) | ||
GatewayTest:testAgentExecutionBadPayload() (gas: 22077) | ||
GatewayTest:testCreateAgent() (gas: 254909) | ||
GatewayTest:testCreateAgentAlreadyCreated() (gas: 256489) | ||
GatewayTest:testCreateChannel() (gas: 332117) | ||
GatewayTest:testCreateChannelFailsAgentDoesNotExist() (gas: 19185) | ||
GatewayTest:testCreateChannelFailsChannelAlreadyExists() (gas: 335995) | ||
GatewayTest:testDisableOutboundMessaging() (gas: 67040) | ||
GatewayTest:testDisableOutboundMessagingForChannel() (gas: 161374) | ||
GatewayTest:testGetters() (gas: 37883) | ||
GatewayTest:testHandlersNotExternallyCallable() (gas: 52292) | ||
GatewayTest:testInitializeNotExternallyCallable() (gas: 16762) | ||
GatewayTest:testRegisterToken() (gas: 85845) | ||
GatewayTest:testRelayerNotRewarded() (gas: 75289) | ||
GatewayTest:testRelayerRewardedFromAgent() (gas: 310728) | ||
GatewayTest:testSendTokenAddress20() (gas: 128049) | ||
GatewayTest:testSendTokenAddress20FailsInvalidDestination() (gas: 59703) | ||
GatewayTest:testSendTokenAddress32() (gas: 129387) | ||
GatewayTest:testSendTokenAddress32ToAssetHub() (gas: 128776) | ||
GatewayTest:testSetOperatingMode() (gas: 39208) | ||
GatewayTest:testSubmitFailInvalidChannel() (gas: 27926) | ||
GatewayTest:testSubmitFailInvalidNonce() (gas: 318948) | ||
GatewayTest:testSubmitHappyPath() (gas: 312342) | ||
GatewayTest:testUpdateChannel() (gas: 58121) | ||
GatewayTest:testUpdateChannelFailDoesNotExist() (gas: 20107) | ||
GatewayTest:testUpdateChannelSanityChecksForBridgeHubChannel() (gas: 22147) | ||
GatewayTest:testUpgrade() (gas: 208455) | ||
GatewayTest:testUpgradeFailCodeHashMismatch() (gas: 178843) | ||
GatewayTest:testUpgradeFailOnInitializationFailure() (gas: 182568) | ||
GatewayTest:testUserDoesNotProvideEnoughFees() (gas: 218463) | ||
GatewayTest:testUserPaysFees() (gas: 244678) | ||
GatewayTest:testWithdrawAgentFunds() (gas: 64315) | ||
MMRProofTest:testVerifyLeafProof() (gas: 370749) | ||
MMRProofTest:testVerifyLeafProofFailsExceededProofSize() (gas: 358741) | ||
ScaleCodecTest:testCheckedEncodeCompactU32() (gas: 5120) | ||
ScaleCodecTest:testEncodeCompactU32() (gas: 9722) | ||
ScaleCodecTest:testEncodeU128() (gas: 192) | ||
ScaleCodecTest:testEncodeU16() (gas: 434) | ||
ScaleCodecTest:testEncodeU256() (gas: 478) | ||
ScaleCodecTest:testEncodeU32() (gas: 170) | ||
ScaleCodecTest:testEncodeU64() (gas: 280) | ||
VerificationTest:testCreateParachainHeaderMerkleFailInvalidHeader() (gas: 11341) | ||
VerificationTest:testCreateParachainHeaderMerkleLeaf() (gas: 20830) | ||
VerificationTest:testIsCommitmentInHeaderDigest() (gas: 21863) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
98 changes: 98 additions & 0 deletions
98
core/packages/contracts/scripts/generateBeefyTestFixture.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,98 @@ | ||||
#!/usr/bin/env ts-node | ||||
import { ValidatorSet, createRandomSubset, readSetBits } from "./helpers" | ||||
import { BigNumber, ethers } from "ethers" | ||||
import fs from "fs" | ||||
import type { BeefyClient } from "../types/BeefyClient" | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add a new package under You'll need to include this script command in the new package:
Then this dependency should change to:
|
||||
import { accounts } from "./wallets" | ||||
import path from "path" | ||||
const encoder = new ethers.utils.AbiCoder() | ||||
|
||||
const run = async () => { | ||||
const fixtureData = JSON.parse( | ||||
fs.readFileSync( | ||||
path.join(process.env.contract_dir || ".", "test/data/beefy-commitment.json"), | ||||
"utf8" | ||||
) | ||||
) | ||||
const BeefyValidatorSetFile = path.join( | ||||
process.env.contract_dir || ".", | ||||
"test/data/beefy-validator-set.json" | ||||
) | ||||
const BeefyBitFieldFile = path.join( | ||||
process.env.contract_dir || ".", | ||||
"test/data/beefy-final-bitfield.json" | ||||
) | ||||
const BeefyValidatorProofFile = path.join( | ||||
process.env.contract_dir || ".", | ||||
"test/data/beefy-final-proof.json" | ||||
) | ||||
const command = process.argv[2] | ||||
const validatorSetID = fixtureData.params.id | ||||
const validatorSetSize = | ||||
process.env["FixedSet"] == "true" | ||||
? accounts.length | ||||
: process.env["ValidatorSetSize"] | ||||
? parseInt(process.env["ValidatorSetSize"]) | ||||
: 300 | ||||
const commitHash = fixtureData.commitmentHash | ||||
let validatorSet: ValidatorSet | ||||
if (process.env["FixedSet"] == "true") { | ||||
validatorSet = new ValidatorSet( | ||||
validatorSetID, | ||||
validatorSetSize, | ||||
accounts.map((account) => account.privateKey) | ||||
) | ||||
} else { | ||||
validatorSet = new ValidatorSet(validatorSetID, validatorSetSize) | ||||
} | ||||
|
||||
if (command == "GenerateInitialSet") { | ||||
const mmrLeaf: BeefyClient.MMRLeafStruct = fixtureData.params.leaf | ||||
|
||||
const absentSubsetSize = Math.floor((validatorSetSize - 1) / 3) | ||||
const subsetSize = validatorSetSize - absentSubsetSize | ||||
const randomSet = createRandomSubset(validatorSetSize, subsetSize) | ||||
const participants = randomSet.participants | ||||
const absentees = randomSet.absentees | ||||
|
||||
const testFixture = { | ||||
validatorSetSize, | ||||
participants, | ||||
absentees, | ||||
validatorRoot: validatorSet.root, | ||||
} | ||||
fs.writeFileSync(BeefyValidatorSetFile, JSON.stringify(testFixture, null, 2), "utf8") | ||||
console.log("Beefy fixture writing to dest file: " + BeefyValidatorSetFile) | ||||
} else if (command == "GenerateProofs") { | ||||
const testFixture = JSON.parse(fs.readFileSync(BeefyBitFieldFile, "utf8")) | ||||
const bitField = encoder.decode(["uint256[]"], testFixture.final.finalBitFieldRaw)[0] | ||||
console.log(bitField) | ||||
let finalBitfield: BigNumber[] = [] | ||||
for (let i = 0; i < bitField.length; i++) { | ||||
finalBitfield.push(bitField[i]) | ||||
} | ||||
const finalValidatorsProof: BeefyClient.ValidatorProofStruct[] = readSetBits( | ||||
finalBitfield | ||||
).map((i) => validatorSet.createSignatureProof(i, commitHash)) | ||||
console.log("Final Validator proofs:", finalValidatorsProof) | ||||
const finalValidatorsProofRaw = encoder.encode( | ||||
[ | ||||
"tuple(uint8 v, bytes32 r, bytes32 s, uint256 index,address account,bytes32[] proof)[]", | ||||
], | ||||
[finalValidatorsProof] | ||||
) | ||||
fs.writeFileSync( | ||||
BeefyValidatorProofFile, | ||||
JSON.stringify({ finalValidatorsProof, finalValidatorsProofRaw }, null, 2), | ||||
"utf8" | ||||
) | ||||
console.log("Beefy fixture writing to dest file: " + BeefyValidatorProofFile) | ||||
} | ||||
} | ||||
|
||||
run() | ||||
.then(() => process.exit(0)) | ||||
.catch((error) => { | ||||
console.error(error) | ||||
process.exit(1) | ||||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Next steps - to implement in a new ticket - let's move this script and
helpers.ts
to a new package undercore/packages
. We can call the packagetest-helpers
or something like that.The goal is to remove javascript stuff from the contracts project.