فهرست منبع

Fix flaky timestamp tests (#4046)

Francisco 2 سال پیش
والد
کامیت
4ff538af58
3فایلهای تغییر یافته به همراه16 افزوده شده و 11 حذف شده
  1. 1 0
      .github/workflows/checks.yml
  2. 9 6
      test/helpers/governance.js
  3. 6 5
      test/helpers/time.js

+ 1 - 0
.github/workflows/checks.yml

@@ -26,6 +26,7 @@ jobs:
     runs-on: ubuntu-latest
     env:
       FORCE_COLOR: 1
+      NODE_OPTIONS: --max_old_space_size=4096
       GAS: true
     steps:
       - uses: actions/checkout@v3

+ 9 - 6
test/helpers/governance.js

@@ -115,19 +115,22 @@ class GovernorHelper {
       : this.governor.castVote(...concatOpts([proposal.id, vote.support], opts));
   }
 
-  waitForSnapshot(offset = 0) {
+  async waitForSnapshot(offset = 0) {
     const proposal = this.currentProposal;
-    return this.governor.proposalSnapshot(proposal.id).then(timepoint => forward[this.mode](timepoint.addn(offset)));
+    const timepoint = await this.governor.proposalSnapshot(proposal.id);
+    return forward[this.mode](timepoint.addn(offset));
   }
 
-  waitForDeadline(offset = 0) {
+  async waitForDeadline(offset = 0) {
     const proposal = this.currentProposal;
-    return this.governor.proposalDeadline(proposal.id).then(timepoint => forward[this.mode](timepoint.addn(offset)));
+    const timepoint = await this.governor.proposalDeadline(proposal.id);
+    return forward[this.mode](timepoint.addn(offset));
   }
 
-  waitForEta(offset = 0) {
+  async waitForEta(offset = 0) {
     const proposal = this.currentProposal;
-    return this.governor.proposalEta(proposal.id).then(timestamp => forward.timestamp(timestamp.addn(offset)));
+    const timestamp = await this.governor.proposalEta(proposal.id);
+    return forward.timestamp(timestamp.addn(offset));
   }
 
   /**

+ 6 - 5
test/helpers/time.js

@@ -1,16 +1,17 @@
-const { time } = require('@openzeppelin/test-helpers');
+const ozHelpers = require('@openzeppelin/test-helpers');
+const helpers = require('@nomicfoundation/hardhat-network-helpers');
 
 module.exports = {
   clock: {
-    blocknumber: () => web3.eth.getBlock('latest').then(block => block.number),
-    timestamp: () => web3.eth.getBlock('latest').then(block => block.timestamp),
+    blocknumber: () => helpers.time.latestBlock(),
+    timestamp: () => helpers.time.latest(),
   },
   clockFromReceipt: {
     blocknumber: receipt => Promise.resolve(receipt.blockNumber),
     timestamp: receipt => web3.eth.getBlock(receipt.blockNumber).then(block => block.timestamp),
   },
   forward: {
-    blocknumber: time.advanceBlockTo,
-    timestamp: time.increaseTo,
+    blocknumber: ozHelpers.time.advanceBlockTo,
+    timestamp: helpers.time.increaseTo,
   },
 };