|
| 1 | +// Copyright 2019 Kodebox, Inc. |
| 2 | +// This file is part of CodeChain. |
| 3 | +// |
| 4 | +// This program is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU Affero General Public License as |
| 6 | +// published by the Free Software Foundation, either version 3 of the |
| 7 | +// License, or (at your option) any later version. |
| 8 | +// |
| 9 | +// This program is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU Affero General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU Affero General Public License |
| 15 | +// along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +import * as chai from "chai"; |
| 18 | +import { expect } from "chai"; |
| 19 | +import * as chaiAsPromised from "chai-as-promised"; |
| 20 | +import "mocha"; |
| 21 | + |
| 22 | +import { validators } from "../../../tendermint.dynval/constants"; |
| 23 | +import { PromiseExpect } from "../../helper/promise"; |
| 24 | +import { changeParams, setTermTestTimeout, withNodes } from "../setup"; |
| 25 | + |
| 26 | +chai.use(chaiAsPromised); |
| 27 | + |
| 28 | +describe("Change era", function() { |
| 29 | + const promiseExpect = new PromiseExpect(); |
| 30 | + const { nodes, initialParams } = withNodes(this, { |
| 31 | + promiseExpect, |
| 32 | + overrideParams: { |
| 33 | + minNumOfValidators: 3, |
| 34 | + maxNumOfValidators: 5 |
| 35 | + }, |
| 36 | + validators: validators.slice(0, 3).map(signer => ({ |
| 37 | + signer, |
| 38 | + delegation: 5_000, |
| 39 | + deposit: 10_000_000 |
| 40 | + })) |
| 41 | + }); |
| 42 | + |
| 43 | + it("should be enabled", async function() { |
| 44 | + const termWaiter = setTermTestTimeout(this, { |
| 45 | + terms: 3 |
| 46 | + }); |
| 47 | + |
| 48 | + const checkingNode = nodes[0]; |
| 49 | + const changeTxHash = await changeParams(checkingNode, 1, { |
| 50 | + ...initialParams, |
| 51 | + era: 1 |
| 52 | + }); |
| 53 | + |
| 54 | + await checkingNode.waitForTx(changeTxHash); |
| 55 | + |
| 56 | + await termWaiter.waitNodeUntilTerm(checkingNode, { |
| 57 | + target: 3, |
| 58 | + termPeriods: 2 |
| 59 | + }); |
| 60 | + }); |
| 61 | + |
| 62 | + it("must increase monotonically", async function() { |
| 63 | + const termWaiter = setTermTestTimeout(this, { |
| 64 | + terms: 2 |
| 65 | + }); |
| 66 | + |
| 67 | + const checkingNode = nodes[0]; |
| 68 | + const changeTxHash = await changeParams(checkingNode, 1, { |
| 69 | + ...initialParams, |
| 70 | + era: 1 |
| 71 | + }); |
| 72 | + |
| 73 | + await checkingNode.waitForTx(changeTxHash); |
| 74 | + |
| 75 | + await expect( |
| 76 | + changeParams(checkingNode, 2, { |
| 77 | + ...initialParams, |
| 78 | + era: 0 |
| 79 | + }) |
| 80 | + ).eventually.rejected; |
| 81 | + }); |
| 82 | + |
| 83 | + afterEach(function() { |
| 84 | + promiseExpect.checkFulfilled(); |
| 85 | + }); |
| 86 | +}); |
0 commit comments