Skip to content

Commit efb6046

Browse files
committed
Assert that transaction is executed in the expected term
1 parent a75c13a commit efb6046

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

test/src/e2e.dynval/1/dv.m-m'.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ import "mocha";
2424
import { validators } from "../../../tendermint.dynval/constants";
2525
import { faucetAddress, faucetSecret } from "../../helper/constants";
2626
import { PromiseExpect } from "../../helper/promise";
27-
import { setTermTestTimeout, withNodes } from "../setup";
27+
import {
28+
setTermTestTimeout,
29+
withNodes,
30+
termThatIncludeTransaction
31+
} from "../setup";
2832

2933
chai.use(chaiAsPromised);
3034

@@ -147,6 +151,9 @@ describe("Dynamic Validator M -> M' (Changed the subset, M, M’ = maximum numbe
147151
})
148152
);
149153
await nodes[0].waitForTx(delegateToCharlie);
154+
await expect(
155+
termThatIncludeTransaction(nodes[0].sdk, delegateToCharlie)
156+
).eventually.equal(1);
150157
await termWaiter.waitNodeUntilTerm(nodes[0], {
151158
target: 2,
152159
termPeriods: 1

test/src/e2e.dynval/setup.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,3 +466,22 @@ export function setTermTestTimeout(
466466
}
467467
};
468468
}
469+
470+
export async function termThatIncludeTransaction(
471+
sdk: SDK,
472+
txHash: H256
473+
): Promise<number> {
474+
const transaction = await sdk.rpc.chain.getTransaction(txHash);
475+
const minedBlock = transaction!.blockNumber!;
476+
const termMetadata = await stake.getTermMetadata(sdk, minedBlock);
477+
478+
if (minedBlock > termMetadata!.lastTermFinishedBlockNumber) {
479+
return termMetadata!.currentTermId;
480+
} else if (minedBlock === termMetadata!.lastTermFinishedBlockNumber) {
481+
return termMetadata!.currentTermId - 1;
482+
} else {
483+
throw new Error(
484+
"Invalid state. minedBlock should be the same or greater than lastTermFinishedBlockNumber"
485+
);
486+
}
487+
}

0 commit comments

Comments
 (0)