Skip to content

Commit 9de88cc

Browse files
Seulgi Kimsgkim126
authored andcommitted
Add an e2e test to check that payment to regular key is invalid
1 parent 2f5d64e commit 9de88cc

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

test/src/e2e/pay.test.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
import { expect } from "chai";
1818
import "mocha";
19-
import { faucetAddress } from "../helper/constants";
19+
import { PlatformAddress } from "codechain-primitives/lib";
20+
import { aliceAddress, aliceSecret, faucetAddress } from "../helper/constants";
2021
import CodeChain from "../helper/spawn";
2122

2223
describe("Pay", async function() {
@@ -43,6 +44,51 @@ describe("Pay", async function() {
4344
expect(await node.sdk.rpc.chain.getTransaction(pay.hash())).not.null;
4445
});
4546

47+
it("Cannot pay to regular key", async function() {
48+
const charge = await node.sendPayTx({
49+
quantity: 100000,
50+
recipient: aliceAddress
51+
});
52+
expect(await node.sdk.rpc.chain.containsTransaction(charge.hash())).be
53+
.true;
54+
expect(await node.sdk.rpc.chain.getTransaction(charge.hash())).not.null;
55+
56+
const privKey = node.sdk.util.generatePrivateKey();
57+
const pubKey = node.sdk.util.getPublicFromPrivate(privKey);
58+
const aliceSeq = await node.sdk.rpc.chain.getSeq(aliceAddress);
59+
await node.setRegularKey(pubKey, {
60+
seq: aliceSeq,
61+
secret: aliceSecret
62+
});
63+
const addressOfRegularKey = PlatformAddress.fromPublic(pubKey, {
64+
networkId: node.sdk.networkId
65+
});
66+
67+
const seq = await node.sdk.rpc.chain.getSeq(faucetAddress);
68+
const blockNumber = await node.getBestBlockNumber();
69+
70+
await node.sdk.rpc.devel.stopSealing();
71+
72+
const pay = await node.sendPayTx({ quantity: 0, seq });
73+
const fail = await node.sendPayTx({
74+
quantity: 100000,
75+
recipient: addressOfRegularKey,
76+
seq: seq + 1
77+
});
78+
79+
await node.sdk.rpc.devel.startSealing();
80+
await node.waitBlockNumber(blockNumber + 1);
81+
82+
expect(await node.sdk.rpc.chain.containsTransaction(pay.hash())).be
83+
.true;
84+
expect(await node.sdk.rpc.chain.getTransaction(pay.hash())).not.null;
85+
86+
expect(await node.sdk.rpc.chain.containsTransaction(fail.hash())).be
87+
.false;
88+
expect(await node.sdk.rpc.chain.getTransaction(fail.hash())).null;
89+
expect(await node.sdk.rpc.chain.getErrorHint(fail.hash())).not.null;
90+
});
91+
4692
afterEach(function() {
4793
if (this.currentTest!.state === "failed") {
4894
node.testFailed(this.currentTest!.fullTitle());

0 commit comments

Comments
 (0)