Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle close account pay transactions which may not have a rcv address #77

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ function extractAndNormaliseTransaction(
txn.arcv = Buffer.from(ALGORAND_ZERO_ADDRESS_BYTES)
}

if (txn.type === TransactionType.pay && !txn.rcv) {
// from_obj_for_encoding expects rcv to be set, which may not be defined when closing an account.
txn.rcv = Buffer.from(ALGORAND_ZERO_ADDRESS_BYTES)
}

return txn
}

Expand Down
8 changes: 8 additions & 0 deletions tests/scenarios/transform-complex-txn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,14 @@ describe('Complex transaction with many nested inner transactions', () => {
expect(algosdk.encodeAddress(blockTransactions[5].transaction.to.publicKey)).toBe(ALGORAND_ZERO_ADDRESS)
})

it('Transforms pay without a rcv address', async () => {
const blocks = await getBlocksBulk({ startRound: 39723800, maxRound: 39723800 }, algod) // Contains a pay close account inner transaction without a rcv address
const blockTransactions = blocks.flatMap((b) => getBlockTransactions(b.block))

expect(blockTransactions.length).toBe(486)
expect(algosdk.encodeAddress(blockTransactions[371].transaction.to.publicKey)).toBe(ALGORAND_ZERO_ADDRESS)
})

it('Produces the correct txID for a non hgi transaction', async () => {
const blocks = await getBlocksBulk({ startRound: 39430981, maxRound: 39430981 }, algod)
const blockTransactions = blocks.flatMap((b) => getBlockTransactions(b.block))
Expand Down
Loading