Skip to content

Commit 6f3c63e

Browse files
Seonpyo Kimmergify[bot]
authored andcommitted
Add a test suite to partialSignature e2e test
Considering transactions which have dynamic inputs and outputs, a test suite named "dynamic inputs and outputs" is added.
1 parent 1b8b574 commit 6f3c63e

File tree

1 file changed

+158
-0
lines changed

1 file changed

+158
-0
lines changed

test/src/e2e/partialSignature.test.ts

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,44 @@ describe("Partial signature", function() {
163163
expect(await node.sdk.rpc.chain.containsTransaction(hash)).be.true;
164164
});
165165

166+
it("Can't add inputs after signing with the signature tag of all inputs when signing burn", async function() {
167+
const tx = node.sdk.core
168+
.createTransferAssetTransaction()
169+
.addBurns(assets[2])
170+
.addOutputs({
171+
assetType,
172+
shardId: 0,
173+
quantity: 1000,
174+
recipient: address1
175+
});
176+
await node.sdk.key.signTransactionBurn(tx, 0);
177+
tx.addInputs(assets[0]);
178+
await node.sdk.key.signTransactionInput(tx, 0);
179+
180+
await expectTransactionFail(node, tx);
181+
});
182+
183+
it("Can add inputs after signing with the signature tag of signle input when signing burn", async function() {
184+
const tx = node.sdk.core
185+
.createTransferAssetTransaction()
186+
.addBurns(assets[2])
187+
.addOutputs({
188+
assetType,
189+
shardId: 0,
190+
quantity: 1000,
191+
recipient: address1
192+
});
193+
await node.sdk.key.signTransactionBurn(tx, 0, {
194+
signatureTag: { input: "single", output: "all" }
195+
});
196+
tx.addInputs(assets[0]);
197+
await node.sdk.key.signTransactionInput(tx, 0);
198+
199+
const hash = await node.sendAssetTransaction(tx);
200+
expect(await node.sdk.rpc.chain.getTransaction(hash)).not.null;
201+
expect(await node.sdk.rpc.chain.containsTransaction(hash)).be.true;
202+
});
203+
166204
// FIXME: (WIP) It fails
167205
it("Can't add inputs after signing with the signature tag of all inputs", async function() {
168206
const tx = node.sdk.core
@@ -334,6 +372,126 @@ describe("Partial signature", function() {
334372
});
335373
});
336374

375+
describe("dynamic inputs and outputs", function() {
376+
let splitedAssets: Asset[];
377+
const splitCount = 50;
378+
379+
beforeEach(async function() {
380+
const splitTx = node.sdk.core
381+
.createTransferAssetTransaction()
382+
.addInputs(assets[0])
383+
.addOutputs(
384+
_.times(splitCount, () => ({
385+
assetType,
386+
shardId: 0,
387+
quantity: 1000 / splitCount,
388+
recipient: address1
389+
}))
390+
);
391+
392+
await node.sdk.key.signTransactionInput(splitTx, 0);
393+
splitedAssets = splitTx.getTransferredAssets();
394+
await node.sendAssetTransaction(splitTx);
395+
});
396+
[5, 10, 20].forEach(function(length) {
397+
it(`${length} inputs and outputs : one-to-one sign`, async function() {
398+
const tx = node.sdk.core.createTransferAssetTransaction();
399+
for (let i = 0; i < length; i++) {
400+
tx.addInputs(splitedAssets[i]).addOutputs({
401+
assetType,
402+
shardId: 0,
403+
quantity: 1000 / splitCount,
404+
recipient: address2
405+
});
406+
await node.sdk.key.signTransactionInput(tx, i, {
407+
signatureTag: {
408+
input: "single",
409+
output: [i]
410+
}
411+
});
412+
}
413+
414+
const hash = await node.sendAssetTransaction(tx);
415+
expect(await node.sdk.rpc.chain.getTransaction(hash)).not.null;
416+
expect(await node.sdk.rpc.chain.containsTransaction(hash)).be
417+
.true;
418+
}).timeout(length * 1000 + 5_000);
419+
});
420+
421+
[5, 10, 20].forEach(function(length) {
422+
it(`${length} inputs and outputs : one-to-many sign`, async function() {
423+
const tx = node.sdk.core.createTransferAssetTransaction();
424+
for (let i = 0; i < length; i++) {
425+
tx.addInputs(splitedAssets[i]).addOutputs({
426+
assetType,
427+
shardId: 0,
428+
quantity: 1000 / splitCount,
429+
recipient: address2
430+
});
431+
await node.sdk.key.signTransactionInput(tx, i, {
432+
signatureTag: {
433+
input: "single",
434+
output: _.range(i)
435+
}
436+
});
437+
}
438+
439+
const hash = await node.sendAssetTransaction(tx);
440+
expect(await node.sdk.rpc.chain.getTransaction(hash)).not.null;
441+
expect(await node.sdk.rpc.chain.containsTransaction(hash)).be
442+
.true;
443+
}).timeout(length * 1000 + 5_000);
444+
});
445+
446+
[5, 10, 20].forEach(function(length) {
447+
it(`${length} burns, inputs and outputs : one-to-many sign`, async function() {
448+
const tx = node.sdk.core.createTransferAssetTransaction();
449+
for (let i = 0; i < Math.floor(length / 2); i++) {
450+
tx.addInputs(splitedAssets[i]).addOutputs({
451+
assetType,
452+
shardId: 0,
453+
quantity: 1000 / splitCount,
454+
recipient: address2
455+
});
456+
await node.sdk.key.signTransactionInput(tx, i, {
457+
signatureTag: {
458+
input: "single",
459+
output: _.range(i)
460+
}
461+
});
462+
}
463+
464+
tx.addBurns(assets[2]);
465+
await node.sdk.key.signTransactionBurn(tx, 0, {
466+
signatureTag: {
467+
input: "single",
468+
output: _.range(Math.floor(length / 2))
469+
}
470+
});
471+
472+
for (let i = Math.floor(length / 2); i < length; i++) {
473+
tx.addInputs(splitedAssets[i]).addOutputs({
474+
assetType,
475+
shardId: 0,
476+
quantity: 1000 / splitCount,
477+
recipient: address2
478+
});
479+
await node.sdk.key.signTransactionInput(tx, i, {
480+
signatureTag: {
481+
input: "single",
482+
output: _.range(i)
483+
}
484+
});
485+
}
486+
487+
const hash = await node.sendAssetTransaction(tx);
488+
expect(await node.sdk.rpc.chain.getTransaction(hash)).not.null;
489+
expect(await node.sdk.rpc.chain.containsTransaction(hash)).be
490+
.true;
491+
}).timeout(length * 1000 + 5_000);
492+
});
493+
});
494+
337495
afterEach(function() {
338496
if (this.currentTest!.state === "failed") {
339497
node.testFailed(this.currentTest!.fullTitle());

0 commit comments

Comments
 (0)