1
- import { algo , AlgorandClient , waitForConfirmation } from '@algorandfoundation/algokit-utils'
2
- import { AlgorandTransactionCrafter , AssetConfigTransaction , AssetParamsBuilder } from "./index" ;
3
- import { Address , SuggestedParams } from "algosdk" ;
1
+ import { AlgorandClient , waitForConfirmation } from '@algorandfoundation/algokit-utils'
2
+ import {
3
+ AlgorandTransactionCrafter , ApplicationCallTransaction ,
4
+ ApplicationCallTxBuilder ,
5
+ AssetConfigTransaction ,
6
+ AssetParamsBuilder , Transaction
7
+ } from "./index" ;
8
+ import algosdk , { Address , SuggestedParams } from "algosdk" ;
4
9
import { SigningAccount , TransactionSignerAccount } from "@algorandfoundation/algokit-utils/types/account" ;
5
10
import { AlgoAmount } from "@algorandfoundation/algokit-utils/types/amount" ;
6
11
import { encode } from "hi-base32" ;
7
12
import { sha512_256 } from "js-sha512" ;
13
+ import { Arc56Contract } from "@algorandfoundation/algokit-utils/types/app-arc56" ;
14
+ import { decode } from "algorand-msgpack" ;
15
+ import * as msgpack from "algo-msgpack-with-bigint" ;
8
16
9
17
export type KeyPairRecord = {
10
18
id : string
@@ -61,9 +69,10 @@ export function generateChecksum(publicKey: Uint8Array){
61
69
) ;
62
70
}
63
71
64
-
65
-
66
72
describe ( 'Algorand Transaction Crafter' , ( ) => {
73
+ let genesisId : string
74
+ let genesisHash : string
75
+
67
76
let algorand : AlgorandClient
68
77
let deployer : Address & TransactionSignerAccount & {
69
78
account : SigningAccount ;
@@ -76,7 +85,7 @@ describe('Algorand Transaction Crafter', () => {
76
85
77
86
beforeAll ( async ( ) => {
78
87
algorand = AlgorandClient . fromEnvironment ( )
79
- deployer = await algorand . account . fromEnvironment ( 'DEPLOYER' )
88
+ deployer = await algorand . account . fromEnvironment ( 'DEPLOYER' , new AlgoAmount ( { algos : 10000 } ) )
80
89
81
90
masterKeyPair = await generateKey ( )
82
91
secondaryKeyPair = await generateKey ( )
@@ -85,7 +94,9 @@ describe('Algorand Transaction Crafter', () => {
85
94
await algorand . account . ensureFunded ( secondaryKeyPair . id , deployer , new AlgoAmount ( { algos : 10 } ) )
86
95
87
96
params = await algorand . getSuggestedParams ( )
88
- algorandCrafter = new AlgorandTransactionCrafter ( params . genesisID as string , Buffer . from ( params . genesisHash as Uint8Array ) . toString ( 'base64' ) )
97
+ genesisId = params . genesisID as string
98
+ genesisHash = Buffer . from ( params . genesisHash as Uint8Array ) . toString ( 'base64' )
99
+ algorandCrafter = new AlgorandTransactionCrafter ( genesisId , genesisHash )
89
100
} , 10000 )
90
101
91
102
it ( "(OK) Pay Transaction" , async ( ) => {
@@ -107,7 +118,7 @@ describe('Algorand Transaction Crafter', () => {
107
118
expect ( account . status ) . toEqual ( "Offline" )
108
119
const onlineTxn = algorandCrafter
109
120
. changeOnline (
110
- masterKeyPair . id ,
121
+ masterKeyPair . id ,
111
122
// Vote Key
112
123
"CR3Bf/IJqzHC1TORQe83QnAkcB+JLyb+opP8f8q3ke0=" ,
113
124
// Selection Key
@@ -239,4 +250,104 @@ describe('Algorand Transaction Crafter', () => {
239
250
const destroyResult = await algorand . client . algod . sendRawTransaction ( destroySigned ) . do ( )
240
251
await waitForConfirmation ( destroyResult . txid , 20 , algorand . client . algod )
241
252
} )
253
+ it ( "(OK Application Create/Delete)" , async ( ) => {
254
+ const appSpec = {
255
+ "name" : "Empty" ,
256
+ "structs" : { } ,
257
+ "methods" : [ ] ,
258
+ "arcs" : [
259
+ 22 ,
260
+ 28
261
+ ] ,
262
+ "networks" : { } ,
263
+ "state" : {
264
+ "schema" : {
265
+ "global" : {
266
+ "ints" : 0 ,
267
+ "bytes" : 0
268
+ } ,
269
+ "local" : {
270
+ "ints" : 0 ,
271
+ "bytes" : 0
272
+ }
273
+ } ,
274
+ "keys" : {
275
+ "global" : { } ,
276
+ "local" : { } ,
277
+ "box" : { }
278
+ } ,
279
+ "maps" : {
280
+ "global" : { } ,
281
+ "local" : { } ,
282
+ "box" : { }
283
+ }
284
+ } ,
285
+ "bareActions" : {
286
+ "create" : [
287
+ "NoOp"
288
+ ] ,
289
+ "call" : [ ]
290
+ } ,
291
+ "sourceInfo" : {
292
+ "approval" : {
293
+ "sourceInfo" : [
294
+ {
295
+ "pc" : [
296
+ 14
297
+ ] ,
298
+ "errorMessage" : "can only call when creating"
299
+ }
300
+ ] ,
301
+ "pcOffsetMethod" : "none"
302
+ } ,
303
+ "clear" : {
304
+ "sourceInfo" : [ ] ,
305
+ "pcOffsetMethod" : "none"
306
+ }
307
+ } ,
308
+ "source" : {
309
+ "approval" : "I3ByYWdtYSB2ZXJzaW9uIDEwCiNwcmFnbWEgdHlwZXRyYWNrIGZhbHNlCgovLyBjb250cmFjdHMuZW1wdHkuRW1wdHkuX19hbGdvcHlfZW50cnlwb2ludF93aXRoX2luaXQoKSAtPiB1aW50NjQ6Cm1haW46CiAgICAvLyAvaG9tZS96ZXJvL1Byb2plY3RzL3N0b3JlLWtpdC9jb250cmFjdHMvZW1wdHkucHk6MwogICAgLy8gY2xhc3MgRW1wdHkoQVJDNENvbnRyYWN0KToKICAgIHR4biBOdW1BcHBBcmdzCiAgICBibnogbWFpbl9hZnRlcl9pZl9lbHNlQDYKICAgIHR4biBPbkNvbXBsZXRpb24KICAgIGJueiBtYWluX2FmdGVyX2lmX2Vsc2VANgogICAgdHhuIEFwcGxpY2F0aW9uSUQKICAgICEKICAgIGFzc2VydCAvLyBjYW4gb25seSBjYWxsIHdoZW4gY3JlYXRpbmcKICAgIHB1c2hpbnQgMSAvLyAxCiAgICByZXR1cm4KCm1haW5fYWZ0ZXJfaWZfZWxzZUA2OgogICAgLy8gL2hvbWUvemVyby9Qcm9qZWN0cy9zdG9yZS1raXQvY29udHJhY3RzL2VtcHR5LnB5OjMKICAgIC8vIGNsYXNzIEVtcHR5KEFSQzRDb250cmFjdCk6CiAgICBwdXNoaW50IDAgLy8gMAogICAgcmV0dXJuCg==" ,
310
+ "clear" : "I3ByYWdtYSB2ZXJzaW9uIDEwCiNwcmFnbWEgdHlwZXRyYWNrIGZhbHNlCgovLyBhbGdvcHkuYXJjNC5BUkM0Q29udHJhY3QuY2xlYXJfc3RhdGVfcHJvZ3JhbSgpIC0+IHVpbnQ2NDoKbWFpbjoKICAgIHB1c2hpbnQgMSAvLyAxCiAgICByZXR1cm4K"
311
+ } ,
312
+ "byteCode" : {
313
+ "approval" : "CjEbQAAMMRlAAAcxGBREgQFDgQBD" ,
314
+ "clear" : "CoEBQw=="
315
+ } ,
316
+ "compilerInfo" : {
317
+ "compiler" : "puya" ,
318
+ "compilerVersion" : {
319
+ "major" : 4 ,
320
+ "minor" : 4 ,
321
+ "patch" : 0
322
+ }
323
+ } ,
324
+ "events" : [ ] ,
325
+ "templateVariables" : { }
326
+ } as Arc56Contract
327
+
328
+ // Create Transaction Factory using Master KeyPair
329
+ const client = algorand . client . getAppFactory ( {
330
+ appSpec,
331
+ defaultSender : deployer . addr ,
332
+ defaultSigner : deployer . signer
333
+ } )
334
+
335
+ const compilationResult = await client . compile ( )
336
+
337
+ const applicationCallTransaction = new ApplicationCallTxBuilder ( genesisId , genesisHash )
338
+ . addSender ( masterKeyPair . id )
339
+ . addApprovalProgram ( compilationResult . approvalProgram )
340
+ . addClearStateProgram ( compilationResult . clearStateProgram )
341
+ . addFirstValidRound ( params . firstValid )
342
+ . addLastValidRound ( params . lastValid )
343
+ . addFee ( Number ( params . fee ) < 1000 ? 1000 : params . fee )
344
+ . get ( )
345
+
346
+
347
+ const encodedTxn = applicationCallTransaction . encode ( )
348
+ const signature = await sign ( encodedTxn , masterKeyPair )
349
+ const signed = algorandCrafter . addSignature ( encodedTxn , signature )
350
+ const { txid} = await algorand . client . algod . sendRawTransaction ( signed ) . do ( )
351
+ await waitForConfirmation ( txid , 20 , algorand . client . algod )
352
+ } )
242
353
} )
0 commit comments