Skip to content

Commit aabfb2c

Browse files
authored
Merge pull request #123 from algorandfoundation/fix/default-sender-creator
fix: correct default sender for inner txns and creator for new contracts
2 parents f583ca8 + 7a26127 commit aabfb2c

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

examples/auction/contract.algo.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OnCompleteAction, TransactionType } from '@algorandfoundation/algorand-typescript'
1+
import { TransactionType } from '@algorandfoundation/algorand-typescript'
22
import { TestExecutionContext } from '@algorandfoundation/algorand-typescript-testing'
33
import { afterEach, describe, expect, it } from 'vitest'
44
import { Auction } from './contract.algo'
@@ -139,9 +139,7 @@ describe('Auction', () => {
139139
contract.createApplication()
140140
})
141141

142-
ctx.txn.createScope([ctx.any.txn.applicationCall({ onCompletion: OnCompleteAction.DeleteApplication })]).execute(() => {
143-
contract!.deleteApplication()
144-
})
142+
contract!.deleteApplication()
145143

146144
// Assert
147145
const innerTransactions = ctx.txn.lastGroup.lastItxnGroup().getPaymentInnerTxn()

src/impl/transactions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { Account, Application, Asset } from './reference'
2020

2121
/** @internal */
2222
const baseDefaultFields = () => ({
23-
sender: lazyContext.defaultSender,
23+
sender: lazyContext.hasActiveGroup ? lazyContext.activeApplication.address : lazyContext.defaultSender,
2424
fee: Uint64(0),
2525
firstValid: Uint64(0),
2626
firstValidTime: Uint64(0),

src/subcontexts/contract-context.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,9 @@ export class ContractContext {
245245
return {
246246
construct(target, args) {
247247
let t: T | undefined = undefined
248-
const application = lazyContext.any.application()
248+
const application = lazyContext.any.application({
249+
creator: lazyContext.hasActiveGroup ? lazyContext.activeGroup.activeTransaction.sender : lazyContext.defaultSender,
250+
})
249251
const txn = lazyContext.any.txn.applicationCall({ appId: application })
250252
const appData = lazyContext.ledger.applicationDataMap.getOrFail(application.id)
251253
appData.isCreating = true

tests/references/arc4-contract.algo.spec.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ describe('arc4 contract creation', () => {
7979
const arg1 = ctx.any.uint64()
8080
const sender = ctx.any.account()
8181

82-
const contract = ctx.contract.create(ContractARC4Create)
83-
ctx.txn.createScope([ctx.any.txn.applicationCall({ appId: ctx.ledger.getApplicationForContract(contract), sender })]).execute(() => {
84-
contract.createApplication(arg1)
85-
expect(contract.arg1).toEqual(arg1)
86-
expect(contract.creator).toEqual(sender)
82+
ctx.txn.createScope([ctx.any.txn.applicationCall({ sender })]).execute(() => {
83+
const contract = ctx.contract.create(ContractARC4Create)
84+
ctx.txn.createScope([ctx.any.txn.applicationCall({ appId: ctx.ledger.getApplicationForContract(contract), sender })]).execute(() => {
85+
contract.createApplication(arg1)
86+
expect(contract.arg1).toEqual(arg1)
87+
expect(contract.creator).toEqual(sender)
88+
})
8789
})
8890
})
8991

0 commit comments

Comments
 (0)