Skip to content

Commit 24edd5f

Browse files
committed
test(appl): add test for appl create
1 parent 44e6baf commit 24edd5f

File tree

1 file changed

+119
-8
lines changed

1 file changed

+119
-8
lines changed

Diff for: lib/e2e.spec.ts

+119-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
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";
49
import {SigningAccount, TransactionSignerAccount} from "@algorandfoundation/algokit-utils/types/account";
510
import {AlgoAmount} from "@algorandfoundation/algokit-utils/types/amount";
611
import {encode} from "hi-base32";
712
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";
816

917
export type KeyPairRecord = {
1018
id: string
@@ -61,9 +69,10 @@ export function generateChecksum(publicKey: Uint8Array){
6169
);
6270
}
6371

64-
65-
6672
describe('Algorand Transaction Crafter', () => {
73+
let genesisId: string
74+
let genesisHash: string
75+
6776
let algorand: AlgorandClient
6877
let deployer: Address & TransactionSignerAccount & {
6978
account: SigningAccount;
@@ -76,7 +85,7 @@ describe('Algorand Transaction Crafter', () => {
7685

7786
beforeAll(async () => {
7887
algorand = AlgorandClient.fromEnvironment()
79-
deployer = await algorand.account.fromEnvironment('DEPLOYER')
88+
deployer = await algorand.account.fromEnvironment('DEPLOYER', new AlgoAmount({algos: 10000}))
8089

8190
masterKeyPair = await generateKey()
8291
secondaryKeyPair = await generateKey()
@@ -85,7 +94,9 @@ describe('Algorand Transaction Crafter', () => {
8594
await algorand.account.ensureFunded(secondaryKeyPair.id, deployer, new AlgoAmount({algos: 10}))
8695

8796
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)
89100
}, 10000)
90101

91102
it("(OK) Pay Transaction", async () => {
@@ -107,7 +118,7 @@ describe('Algorand Transaction Crafter', () => {
107118
expect(account.status).toEqual("Offline")
108119
const onlineTxn = algorandCrafter
109120
.changeOnline(
110-
masterKeyPair.id,
121+
masterKeyPair.id,
111122
// Vote Key
112123
"CR3Bf/IJqzHC1TORQe83QnAkcB+JLyb+opP8f8q3ke0=",
113124
// Selection Key
@@ -239,4 +250,104 @@ describe('Algorand Transaction Crafter', () => {
239250
const destroyResult = await algorand.client.algod.sendRawTransaction(destroySigned).do()
240251
await waitForConfirmation(destroyResult.txid, 20, algorand.client.algod)
241252
})
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+
})
242353
})

0 commit comments

Comments
 (0)