|
1 | 1 | import { ABIMethod, ABITupleType, ABIType } from '@algorandfoundation/algokit-abi' |
2 | 2 | import { Address } from '@algorandfoundation/algokit-common' |
3 | | -import { Transaction, TransactionSigner, TransactionType } from '@algorandfoundation/algokit-transact' |
| 3 | +import { |
| 4 | + decodeSignedTransaction, |
| 5 | + generateAddressWithSigners, |
| 6 | + Transaction, |
| 7 | + TransactionSigner, |
| 8 | + TransactionType, |
| 9 | +} from '@algorandfoundation/algokit-transact' |
4 | 10 | import { beforeEach, describe, expect, test, vi } from 'vitest' |
5 | | -import { AlgoAmount } from './amount' |
| 11 | +import { algo, AlgoAmount } from './amount' |
6 | 12 | import { algorandFixture } from './testing' |
| 13 | +import { nobleEd25519Generator } from '@algorandfoundation/algokit-crypto' |
7 | 14 |
|
8 | 15 | describe('TransactionComposer', () => { |
9 | 16 | const fixture = algorandFixture() |
@@ -613,4 +620,36 @@ describe('TransactionComposer', () => { |
613 | 620 | await expect(composer.gatherSignatures()).rejects.toThrow('Transactions at indexes [0] were not signed') |
614 | 621 | }) |
615 | 622 | }) |
| 623 | + |
| 624 | + test('should use signer from sender', async () => { |
| 625 | + const { algorand } = fixture |
| 626 | + |
| 627 | + // Generate an account outside of the algorand client and fund it |
| 628 | + const generated = nobleEd25519Generator() |
| 629 | + const addressWithSigners = generateAddressWithSigners(generated) |
| 630 | + |
| 631 | + await algorand.account.ensureFundedFromEnvironment(addressWithSigners.addr, algo(1)) |
| 632 | + |
| 633 | + // First verify that the signer isn't found when we only pass the address |
| 634 | + const addrOnlyComposer = algorand.newGroup() |
| 635 | + addrOnlyComposer.addPayment({ |
| 636 | + sender: addressWithSigners.addr, |
| 637 | + receiver: addressWithSigners.addr, |
| 638 | + amount: algo(0), |
| 639 | + }) |
| 640 | + await expect(addrOnlyComposer.gatherSignatures()).rejects.toThrow(`No signer found for address ${addressWithSigners.addr}`) |
| 641 | + |
| 642 | + // Then verify that the signer is found when we pass the address with the signer |
| 643 | + const composer = algorand.newGroup() |
| 644 | + composer.addPayment({ |
| 645 | + sender: addressWithSigners, |
| 646 | + receiver: addressWithSigners, |
| 647 | + amount: algo(0), |
| 648 | + }) |
| 649 | + |
| 650 | + const signedTxns = await composer.gatherSignatures() |
| 651 | + |
| 652 | + expect(signedTxns).toHaveLength(1) |
| 653 | + expect(decodeSignedTransaction(signedTxns[0]).sig!.length).toBe(64) |
| 654 | + }) |
616 | 655 | }) |
0 commit comments