Skip to content

Commit

Permalink
fix: revert back to previous state delta behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
neilcampbell committed Feb 1, 2025
1 parent 2f82291 commit c2a4bb5
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 62 deletions.
20 changes: 16 additions & 4 deletions src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,14 @@ export function getIndexerTransactionFromAlgodTransaction(t: TransactionInBlock,
key: Buffer.from(key).toString('base64'),
value: new algosdk.indexerModels.EvalDelta({
action: value.action,
bytes: value.bytes ? Buffer.from(value.bytes).toString('base64') : undefined,
uint: value.uint,
...(value.uint && value.uint > 0n && (!value.bytes || value.bytes.length === 0)
? {
uint: value.uint,
}
: {
bytes: value.bytes ? Buffer.from(value.bytes).toString('base64') : undefined,
uint: value.uint,
}),
}),
}),
)
Expand All @@ -489,8 +495,14 @@ export function getIndexerTransactionFromAlgodTransaction(t: TransactionInBlock,
key: Buffer.from(key).toString('base64'),
value: new algosdk.indexerModels.EvalDelta({
action: value.action,
bytes: value.bytes ? Buffer.from(value.bytes).toString('base64') : undefined,
uint: value.uint,
...(value.uint && value.uint > 0n && (!value.bytes || value.bytes.length === 0)
? {
uint: value.uint,
}
: {
bytes: value.bytes ? Buffer.from(value.bytes).toString('base64') : undefined,
uint: value.uint,
}),
}),
}),
),
Expand Down
116 changes: 58 additions & 58 deletions tests/scenarios/transform-complex-txn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -795,48 +795,46 @@ describe('Complex transaction with many nested inner transactions', () => {
const localStateDelta = transactionForDiff.localStateDelta
const globalStateDelta = transactionForDiff.globalStateDelta
expect(globalStateDelta).toMatchInlineSnapshot(`
[
{
"key": "Y3VycmVudF9taW5lcl9lZmZvcnQ=",
"value": {
"action": 2,
"bytes": "",
"uint": 412000n,
},
},
{
"key": "dG90YWxfZWZmb3J0",
"value": {
"action": 2,
"bytes": "",
"uint": 2129702852933n,
},
},
{
"key": "dG90YWxfdHJhbnNhY3Rpb25z",
"value": {
"action": 2,
"bytes": "",
"uint": 324424783n,
},
},
]`)
[
{
"key": "Y3VycmVudF9taW5lcl9lZmZvcnQ=",
"value": {
"action": 2,
"uint": 412000n,
},
},
{
"key": "dG90YWxfZWZmb3J0",
"value": {
"action": 2,
"uint": 2129702852933n,
},
},
{
"key": "dG90YWxfdHJhbnNhY3Rpb25z",
"value": {
"action": 2,
"uint": 324424783n,
},
},
]
`)
expect(localStateDelta).toMatchInlineSnapshot(`
[
{
"address": "R4Q3KN5RBXUQIJWSVMQUJ7FTL7YURP6DY6W724HTD4Z43IRGUCZ2ORANGE",
"delta": [
{
"key": "ZWZmb3J0",
"value": {
"action": 2,
"bytes": "",
"uint": 412000n,
[
{
"address": "R4Q3KN5RBXUQIJWSVMQUJ7FTL7YURP6DY6W724HTD4Z43IRGUCZ2ORANGE",
"delta": [
{
"key": "ZWZmb3J0",
"value": {
"action": 2,
"uint": 412000n,
},
},
],
},
},
],
},
]`)
]
`)
})

it('Produces base64 encoded programs for an application create transaction', async () => {
Expand All @@ -861,23 +859,25 @@ describe('Complex transaction with many nested inner transactions', () => {

const transaction = getIndexerTransactionFromAlgodTransaction(txn)
const globalStateDelta = transaction.globalStateDelta
expect(globalStateDelta).toMatchInlineSnapshot(`[
EvalDeltaKeyValue {
"key": "cg==",
"value": EvalDelta {
"action": 2,
"bytes": "",
"uint": 6311n,
},
},
EvalDeltaKeyValue {
"key": "cmk=",
"value": EvalDelta {
"action": 1,
"bytes": "gfOn0O9iF4/OGJ6kRsOFfbp/zhAedEwoZL/escO+M+QAAAAAQ/9CAQAAAAACsUi5AwAkCj8UAphDyseTKWeF7KZFZuNK8zA9rbqocWk+NJ5CpMtNsCSq7S8AAAAAAAAAJxAAAABi6BgWCgAAAAAAAAAA",
"uint": 0n,
},
},
]`)
expect(globalStateDelta).toMatchInlineSnapshot(`
[
EvalDeltaKeyValue {
"key": "cg==",
"value": EvalDelta {
"action": 2,
"bytes": undefined,
"uint": 6311n,
},
},
EvalDeltaKeyValue {
"key": "cmk=",
"value": EvalDelta {
"action": 1,
"bytes": "gfOn0O9iF4/OGJ6kRsOFfbp/zhAedEwoZL/escO+M+QAAAAAQ/9CAQAAAAACsUi5AwAkCj8UAphDyseTKWeF7KZFZuNK8zA9rbqocWk+NJ5CpMtNsCSq7S8AAAAAAAAAJxAAAABi6BgWCgAAAAAAAAAA",
"uint": 0n,
},
},
]
`)
})
})

0 comments on commit c2a4bb5

Please sign in to comment.