ecash-agora 2.2.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -51,7 +51,10 @@ async function makeBuilderInputs(
51
51
  runner: TestRunner,
52
52
  values: bigint[],
53
53
  ): Promise<TxBuilderInput[]> {
54
- const txid = await runner.sendToScript(values, makerScript);
54
+ const txid = await runner.sendToTwoScripts(
55
+ { script: makerScript, sats: values[0] },
56
+ { script: takerScript, sats: values[1] },
57
+ );
55
58
  return values.map((sats, outIdx) => ({
56
59
  input: {
57
60
  prevOut: {
@@ -82,10 +85,7 @@ describe('Agora Partial 7450M XEC vs 2p64-1 full accept', () => {
82
85
  });
83
86
 
84
87
  it('Agora Partial 7450M XEC vs 2p64-1 full accept', async () => {
85
- const [fuelInput, takerInput] = await makeBuilderInputs(runner, [
86
- 10000n,
87
- BIGSATS,
88
- ]);
88
+ const [fuelInput] = await makeBuilderInputs(runner, [10000n, BIGSATS]);
89
89
 
90
90
  const agora = new Agora(chronik);
91
91
  const agoraPartial = await agora.selectParams({
@@ -131,7 +131,6 @@ describe('Agora Partial 7450M XEC vs 2p64-1 full accept', () => {
131
131
  chronik,
132
132
  offer,
133
133
  takerSk,
134
- takerInput,
135
134
  acceptedAtoms: agoraPartial.offeredAtoms(),
136
135
  });
137
136
 
@@ -173,10 +172,7 @@ describe('Agora Partial 7450M XEC vs 2p64-1 small accept', () => {
173
172
  });
174
173
 
175
174
  it('Agora Partial 7450M XEC vs 2p64-1 small accept', async () => {
176
- const [fuelInput, takerInput] = await makeBuilderInputs(runner, [
177
- 10000n,
178
- BIGSATS,
179
- ]);
175
+ const [fuelInput] = await makeBuilderInputs(runner, [10000n, BIGSATS]);
180
176
 
181
177
  const agora = new Agora(chronik);
182
178
  const agoraPartial = await agora.selectParams({
@@ -224,7 +220,6 @@ describe('Agora Partial 7450M XEC vs 2p64-1 small accept', () => {
224
220
  chronik,
225
221
  offer,
226
222
  takerSk,
227
- takerInput,
228
223
  acceptedAtoms,
229
224
  });
230
225
 
@@ -274,10 +269,7 @@ describe('Agora Partial 7450M XEC vs 2p63-1 full accept', () => {
274
269
  });
275
270
 
276
271
  it('Agora Partial 7450M XEC vs 2p63-1 full accept', async () => {
277
- const [fuelInput, takerInput] = await makeBuilderInputs(runner, [
278
- 10000n,
279
- BIGSATS,
280
- ]);
272
+ const [fuelInput] = await makeBuilderInputs(runner, [10000n, BIGSATS]);
281
273
 
282
274
  const agora = new Agora(chronik);
283
275
  const agoraPartial = await agora.selectParams({
@@ -326,7 +318,6 @@ describe('Agora Partial 7450M XEC vs 2p63-1 full accept', () => {
326
318
  chronik,
327
319
  offer,
328
320
  takerSk,
329
- takerInput,
330
321
  acceptedAtoms,
331
322
  });
332
323
 
@@ -369,10 +360,7 @@ describe('Agora Partial 7450M XEC vs 2p63-1 small accept', () => {
369
360
  });
370
361
 
371
362
  it('Agora Partial 7450M XEC vs 2p63-1 small accept', async () => {
372
- const [fuelInput, takerInput] = await makeBuilderInputs(runner, [
373
- 10000n,
374
- BIGSATS,
375
- ]);
363
+ const [fuelInput] = await makeBuilderInputs(runner, [10000n, BIGSATS]);
376
364
 
377
365
  const agora = new Agora(chronik);
378
366
  const agoraPartial = await agora.selectParams({
@@ -420,7 +408,6 @@ describe('Agora Partial 7450M XEC vs 2p63-1 small accept', () => {
420
408
  chronik,
421
409
  offer,
422
410
  takerSk,
423
- takerInput,
424
411
  acceptedAtoms,
425
412
  });
426
413
 
@@ -470,10 +457,7 @@ describe('Agora Partial 7450M XEC vs 100 full accept', () => {
470
457
  });
471
458
 
472
459
  it('Agora Partial 7450M XEC vs 100 full accept', async () => {
473
- const [fuelInput, takerInput] = await makeBuilderInputs(runner, [
474
- 10000n,
475
- BIGSATS,
476
- ]);
460
+ const [fuelInput] = await makeBuilderInputs(runner, [10000n, BIGSATS]);
477
461
 
478
462
  const agora = new Agora(chronik);
479
463
  const agoraPartial = await agora.selectParams({
@@ -517,7 +501,6 @@ describe('Agora Partial 7450M XEC vs 100 full accept', () => {
517
501
  chronik,
518
502
  offer,
519
503
  takerSk,
520
- takerInput,
521
504
  acceptedAtoms: 100n,
522
505
  });
523
506
  const acceptTx = await chronik.tx(acceptTxid);
@@ -559,10 +542,7 @@ describe('Agora Partial 7450M XEC vs 100 small accept', () => {
559
542
  });
560
543
 
561
544
  it('Agora Partial 7450M XEC vs 100 small accept', async () => {
562
- const [fuelInput, takerInput] = await makeBuilderInputs(runner, [
563
- 10000n,
564
- BIGSATS,
565
- ]);
545
+ const [fuelInput] = await makeBuilderInputs(runner, [10000n, BIGSATS]);
566
546
 
567
547
  const agora = new Agora(chronik);
568
548
  const agoraPartial = await agora.selectParams({
@@ -602,7 +582,6 @@ describe('Agora Partial 7450M XEC vs 100 small accept', () => {
602
582
  chronik,
603
583
  offer,
604
584
  takerSk,
605
- takerInput,
606
585
  acceptedAtoms: 1n,
607
586
  });
608
587
  const acceptTx = await chronik.tx(acceptTxid);
@@ -23,6 +23,7 @@ import { TestRunner } from 'ecash-lib/dist/test/testRunner.js';
23
23
  import { AgoraPartial } from '../src/partial.js';
24
24
  import { makeSlpOffer, takeSlpOffer } from './partial-helper-slp.js';
25
25
  import { Agora, TakenInfo } from '../src/agora.js';
26
+ import { Wallet } from 'ecash-wallet/src/wallet.js';
26
27
 
27
28
  use(chaiAsPromised);
28
29
 
@@ -56,7 +57,10 @@ describe('AgoraPartial SLP', () => {
56
57
  async function makeBuilderInputs(
57
58
  values: bigint[],
58
59
  ): Promise<TxBuilderInput[]> {
60
+ // NB for these "not big sats" tests, we can just send to both, no need to sendToTwoScripts
59
61
  const txid = await runner.sendToScript(values, makerScript);
62
+ // Send some cash to the taker, since the accept() tests spend from this wallet
63
+ await runner.sendToScript(values, takerScript);
60
64
  return values.map((sats, outIdx) => ({
61
65
  input: {
62
66
  prevOut: {
@@ -472,6 +476,7 @@ describe('AgoraPartial SLP', () => {
472
476
  },
473
477
  ];
474
478
 
479
+ let cancelTxsMatchCount = 0;
475
480
  for (const testCase of TEST_CASES) {
476
481
  it(`AgoraPartial SLP ${testCase.offeredAtoms} for ${testCase.info}`, async () => {
477
482
  const agora = new Agora(chronik);
@@ -484,10 +489,7 @@ describe('AgoraPartial SLP', () => {
484
489
  });
485
490
  const askedSats = agoraPartial.askedSats(testCase.acceptedAtoms);
486
491
  const requiredSats = askedSats + 2000n;
487
- const [fuelInput, takerInput] = await makeBuilderInputs([
488
- 4000n,
489
- requiredSats,
490
- ]);
492
+ const [fuelInput] = await makeBuilderInputs([4000n, requiredSats]);
491
493
 
492
494
  const offer = await makeSlpOffer({
493
495
  chronik,
@@ -499,7 +501,6 @@ describe('AgoraPartial SLP', () => {
499
501
  chronik,
500
502
  takerSk,
501
503
  offer,
502
- takerInput,
503
504
  acceptedAtoms: testCase.acceptedAtoms,
504
505
  allowUnspendable: testCase.allowUnspendable,
505
506
  });
@@ -586,17 +587,40 @@ describe('AgoraPartial SLP', () => {
586
587
  recipientScript: makerScript,
587
588
  extraInputs: [fuelInput], // dummy input for measuring
588
589
  });
589
- const cancelTxSer = newOffer
590
- .cancelTx({
591
- cancelSk: makerSk,
592
- fuelInputs: await makeBuilderInputs([cancelFeeSats]),
593
- recipientScript: makerScript,
594
- })
595
- .ser();
596
- const cancelTxid = (await chronik.broadcastTx(cancelTxSer)).txid;
597
- const cancelTx = await chronik.tx(cancelTxid);
598
- expect(cancelTx.outputs[1].token?.atoms).to.equal(leftoverTokens);
599
- expect(cancelTx.outputs[1].outputScript).to.equal(makerScriptHex);
590
+ const cancelTx = newOffer.cancelTx({
591
+ cancelSk: makerSk,
592
+ fuelInputs: await makeBuilderInputs([cancelFeeSats]),
593
+ recipientScript: makerScript,
594
+ });
595
+ const cancelTxid = cancelTx.txid();
596
+
597
+ // Let's build and broadcast using cancel() instead
598
+ const cancelWallet = Wallet.fromSk(makerSk, chronik);
599
+ await cancelWallet.sync();
600
+ const cancelResult = await newOffer.cancel({
601
+ wallet: cancelWallet,
602
+ });
603
+ const broadcastCancelTxid = cancelResult.broadcasted[0];
604
+ if (broadcastCancelTxid === cancelTxid) {
605
+ cancelTxsMatchCount++;
606
+ console.log(
607
+ `${cancelTxsMatchCount} of ${TEST_CASES.length} produce equal txids with cancelTx() and cancel()`,
608
+ );
609
+
610
+ // Between ~5 and ~8 of 46 of these txs are identical from each method
611
+
612
+ // On inspection, when cancel() txid does not match,
613
+ // it is because cancel has selected different fuel inputs
614
+ // This is expected behavior, these txs still show change
615
+ // going to the cancel wallet as expected
616
+ }
617
+ const cancelChronikTx = await chronik.tx(broadcastCancelTxid);
618
+ expect(cancelChronikTx.outputs[1].token?.atoms).to.equal(
619
+ leftoverTokens,
620
+ );
621
+ expect(cancelChronikTx.outputs[1].outputScript).to.equal(
622
+ makerScriptHex,
623
+ );
600
624
 
601
625
  // takerIndex is 2 for full accept, 3 for partial accept
602
626
  const takerIndex = isFullAccept ? 2 : 3;
@@ -655,10 +679,7 @@ describe('AgoraPartial SLP', () => {
655
679
  });
656
680
  const askedSats = agoraPartial.askedSats(thisTestCase.acceptedAtoms);
657
681
  const requiredSats = askedSats + 2000n;
658
- const [fuelInput, takerInput] = await makeBuilderInputs([
659
- 4000n,
660
- requiredSats,
661
- ]);
682
+ const [fuelInput] = await makeBuilderInputs([4000n, requiredSats]);
662
683
 
663
684
  const offer = await makeSlpOffer({
664
685
  chronik,
@@ -683,7 +704,6 @@ describe('AgoraPartial SLP', () => {
683
704
  chronik,
684
705
  takerSk,
685
706
  offer,
686
- takerInput,
687
707
  acceptedAtoms: thisTestCase.acceptedAtoms,
688
708
  allowUnspendable: false,
689
709
  }),
@@ -713,10 +733,7 @@ describe('AgoraPartial SLP', () => {
713
733
  const acceptedAtoms = 500n;
714
734
  const askedSats = agoraPartial.askedSats(acceptedAtoms);
715
735
  const requiredSats = askedSats + 2000n;
716
- const [fuelInput, takerInput] = await makeBuilderInputs([
717
- 4000n,
718
- requiredSats,
719
- ]);
736
+ const [fuelInput] = await makeBuilderInputs([4000n, requiredSats]);
720
737
 
721
738
  const offer = await makeSlpOffer({
722
739
  chronik,
@@ -739,7 +756,6 @@ describe('AgoraPartial SLP', () => {
739
756
  chronik,
740
757
  takerSk,
741
758
  offer,
742
- takerInput,
743
759
  acceptedAtoms: acceptedAtoms,
744
760
  allowUnspendable: false,
745
761
  }),
@@ -752,7 +768,6 @@ describe('AgoraPartial SLP', () => {
752
768
  chronik,
753
769
  takerSk,
754
770
  offer,
755
- takerInput,
756
771
  acceptedAtoms: acceptedAtoms,
757
772
  allowUnspendable: undefined,
758
773
  }),
@@ -765,7 +780,6 @@ describe('AgoraPartial SLP', () => {
765
780
  chronik,
766
781
  takerSk,
767
782
  offer,
768
- takerInput,
769
783
  acceptedAtoms: acceptedAtoms,
770
784
  }),
771
785
  expectedError,