Hi!
In TealScript I can write methods like this:
/**
* Buy 1 piece of the asset
* @param payment Payment in /uAlgos
*/
buyAsset(payment: PayTxn): void {
/// Ensure asset selling period hasn't ended yet
assert(globals.latestTimestamp < this.sellPeriodEnd.value);
/// Verify payment transaction
verifyPayTxn(payment, {
sender: this.txn.sender,
receiver: globals.creatorAddress,
amount: { greaterThanEqualTo: this.assetPrice.value, lessThanEqualTo: this.assetPrice.value },
rekeyTo: globals.zeroAddress,
closeRemainderTo: globals.zeroAddress,
});
/// Verify asset amount
assert(this.assetAmount.value > 0);
/// @todo: check asset amount in buyer account
/// Send asset to payer
sendAssetTransfer({
assetReceiver: this.txn.sender,
xferAsset: this.asset.value,
assetAmount: 1,
});
// Decrease asset amount
this.assetAmount.value = this.assetAmount.value - 1;
}
My question is, how can this be called from TypeScript Jest framework? From the compiled TEAL code I see that TEAL waits for a txn grup, and checks whether the last txn in the group is a payment txn. So a transaction group is needed, where the first tx is the app call, the second is the payment txn, but I still don’t know how to make it in TypeScript?