Skip to content

Commit

Permalink
Merge pull request #32 from algorandfoundation/fix/acct-data
Browse files Browse the repository at this point in the history
fix: allow v11 acct param fields to be set in any.account() call
  • Loading branch information
boblat authored Jan 15, 2025
2 parents 7086c0c + d60f869 commit d90b5f6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/value-generators/avm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { asBigInt, asUint64Cls, getRandomBigInt, getRandomBytes } from '../util'
type AccountContextData = Partial<AccountData['account']> & {
address?: Account
incentiveEligible?: boolean
lastProposed?: uint64
lastHeartbeat?: uint64
optedAssetBalances?: Map<internal.primitives.StubUint64Compat, internal.primitives.StubUint64Compat>
optedApplications?: Application[]
}
Expand Down Expand Up @@ -57,8 +59,10 @@ export class AvmValueGenerator {
}

const data = new AccountData()
const { address, optedAssetBalances, optedApplications, incentiveEligible, ...accountData } = input ?? {}
const { address, optedAssetBalances, optedApplications, incentiveEligible, lastProposed, lastHeartbeat, ...accountData } = input ?? {}
data.incentiveEligible = incentiveEligible ?? false
data.lastProposed = lastProposed
data.lastHeartbeat = lastHeartbeat
data.account = {
...data.account,
...accountData,
Expand Down
8 changes: 7 additions & 1 deletion tests/state-op-codes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ describe('State op codes', async () => {
address: dummyAccount,
balance: Uint64(INITIAL_BALANCE_MICRO_ALGOS + 100000),
})
const incentiveEligible = op.AcctParams.acctIncentiveEligible(mockAccount)
const lastProposed = op.AcctParams.acctLastProposed(mockAccount)
const lastHeartbeat = op.AcctParams.acctLastHeartbeat(mockAccount)
expect(incentiveEligible).toEqual([false, true])
expect(lastProposed).toEqual([Global.round, true])
expect(lastHeartbeat).toEqual([Global.round, true])
})
Expand All @@ -146,10 +148,14 @@ describe('State op codes', async () => {
const mockAccount = ctx.any.account({
address: dummyAccount,
balance: Uint64(INITIAL_BALANCE_MICRO_ALGOS + 100000),
incentiveEligible: true,
lastProposed: 100,
lastHeartbeat: 200,
})
ctx.ledger.patchAccountData(mockAccount, { lastProposed: 100, lastHeartbeat: 200 })
const incentiveEligible = op.AcctParams.acctIncentiveEligible(mockAccount)
const lastProposed = op.AcctParams.acctLastProposed(mockAccount)
const lastHeartbeat = op.AcctParams.acctLastHeartbeat(mockAccount)
expect(incentiveEligible).toEqual([true, true])
expect(lastProposed).toEqual([100, true])
expect(lastHeartbeat).toEqual([200, true])
})
Expand Down

0 comments on commit d90b5f6

Please sign in to comment.