1
- import { describe, test, expect, beforeAll } from ' vitest' ;
2
- import { algorandFixture } from ' @algorandfoundation/algokit-utils/testing' ;
3
- import * as algosdk from ' algosdk' ;
4
- import * as algodPackage from ' @algorandfoundation/algokit-algod-api-ts' ;
5
- import { encodeTransaction, Transaction, Address } from ' algokit_transact' ;
6
- import { Blob } from ' buffer' ;
7
- import { HttpFile } from ' ../http/http' ;
8
- import { TransactionSignerAccount } from ' @algorandfoundation/algokit-utils/types/account' ;
1
+ import { describe, test, expect, beforeAll } from " vitest" ;
2
+ import { algorandFixture } from " @algorandfoundation/algokit-utils/testing" ;
3
+ import * as algosdk from " algosdk" ;
4
+ import * as algodPackage from " @algorandfoundation/algokit-algod-api" ;
5
+ import { encodeTransaction, Transaction, Address } from " algokit_transact" ;
6
+ import { Blob } from " buffer" ;
7
+ import { HttpFile } from " ../http/http" ;
8
+ import { TransactionSignerAccount } from " @algorandfoundation/algokit-utils/types/account" ;
9
9
10
10
// Helper function to create and sign a transaction, then return it as an HttpFile
11
11
const createSignedTxnHttpFile = (
12
12
sender: algosdk.Address & TransactionSignerAccount & algosdk.Account,
13
13
receiver: Address,
14
14
amount: number | bigint,
15
15
apiSuggestedParams: algodPackage.TransactionParams200Response,
16
- note?: Uint8Array
16
+ note?: Uint8Array,
17
17
): HttpFile => {
18
18
const transactionHeaderParams = {
19
19
fee: BigInt(apiSuggestedParams.minFee || apiSuggestedParams.fee),
20
20
firstValid: BigInt(apiSuggestedParams.lastRound),
21
21
lastValid: BigInt(apiSuggestedParams.lastRound) + BigInt(1000),
22
- genesisHash: new Uint8Array(Buffer.from(apiSuggestedParams.genesisHash, ' base64' )),
22
+ genesisHash: new Uint8Array(Buffer.from(apiSuggestedParams.genesisHash, " base64" )),
23
23
genesisId: apiSuggestedParams.genesisId,
24
- }
24
+ } ;
25
25
26
26
const txn: Transaction = {
27
- transactionType: ' Payment' ,
27
+ transactionType: " Payment" ,
28
28
payment: {
29
29
amount: BigInt(amount),
30
30
receiver: receiver,
@@ -38,81 +38,76 @@ const createSignedTxnHttpFile = (
38
38
const algosdkTxn = algosdk.decodeUnsignedTransaction(Buffer.from(encodedTxn.slice(2)));
39
39
const signedTxnBytes = algosdkTxn.signTxn(sender.sk);
40
40
41
- const binaryData = new Blob([signedTxnBytes], { type: ' application/x-binary' } );
41
+ const binaryData = new Blob([signedTxnBytes], { type: " application/x-binary" } );
42
42
// @ts-ignore - we know this matches the HttpFile structure
43
43
// TODO: find more elegant way to do this
44
- const httpFile: HttpFile = Object.assign(binaryData, { name: ' transaction.txn' } );
44
+ const httpFile: HttpFile = Object.assign(binaryData, { name: " transaction.txn" } );
45
45
return httpFile;
46
46
};
47
47
48
- describe(' Transaction API Tests' , () => {
48
+ describe(" Transaction API Tests" , () => {
49
49
const fixture = algorandFixture();
50
50
let algodApi: algodPackage.AlgodApi;
51
51
52
52
beforeAll(async () => {
53
53
await fixture.newScope();
54
54
const authConfig: algodPackage.AuthMethodsConfiguration = {
55
- " api_key" : " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
56
- }
57
- const serverConfig = new algodPackage.ServerConfiguration(' http://localhost:4001' , { } )
55
+ api_key: " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ,
56
+ } ;
57
+ const serverConfig = new algodPackage.ServerConfiguration(" http://localhost:4001" , { } );
58
58
const configurationParameters = {
59
- httpApi: new algodPackage.IsomorphicFetchHttpLibrary(),
60
- baseServer: serverConfig,
61
- authMethods: authConfig,
62
- promiseMiddleware: [],
63
- }
59
+ httpApi: new algodPackage.IsomorphicFetchHttpLibrary(),
60
+ baseServer: serverConfig,
61
+ authMethods: authConfig,
62
+ promiseMiddleware: [],
63
+ } ;
64
64
const config = algodPackage.createConfiguration(configurationParameters);
65
65
algodApi = new algodPackage.AlgodApi(config);
66
66
});
67
67
68
- test(' should get transaction parameters' , async () => {
68
+ test(" should get transaction parameters" , async () => {
69
69
const params = await algodApi.transactionParams();
70
70
expect(params).toBeDefined();
71
- expect(params.consensusVersion).toBeTypeOf(' string' );
72
- expect(params.fee).toBeTypeOf(' number' );
73
- expect(params.genesisHash).toBeTypeOf(' string' );
74
- expect(params.genesisId).toBeTypeOf(' string' );
75
- expect(params.lastRound).toBeTypeOf(' number' );
76
- expect(params.minFee).toBeTypeOf(' number' );
71
+ expect(params.consensusVersion).toBeTypeOf(" string" );
72
+ expect(params.fee).toBeTypeOf(" number" );
73
+ expect(params.genesisHash).toBeTypeOf(" string" );
74
+ expect(params.genesisId).toBeTypeOf(" string" );
75
+ expect(params.lastRound).toBeTypeOf(" number" );
76
+ expect(params.minFee).toBeTypeOf(" number" );
77
77
} );
78
78
79
- test(' should submit a raw transaction' , async () => {
79
+ test(" should submit a raw transaction" , async () => {
80
80
const { testAccount: sender } = fixture.context;
81
81
const suggestedParams = await algodApi.transactionParams();
82
82
83
- const httpFile = createSignedTxnHttpFile(
84
- sender,
85
- { address: String(sender.addr), pubKey: sender.publicKey } ,
86
- 100000,
87
- suggestedParams
88
- );
83
+ const httpFile = createSignedTxnHttpFile(sender, { address: String(sender.addr), pubKey: sender.publicKey } , 100000, suggestedParams);
89
84
90
85
const result = await algodApi.rawTransaction(httpFile);
91
86
expect(result).not.toBeNull();
92
87
expect(result?.txId).toBeDefined();
93
88
});
94
89
95
- test(' should get pending transaction info' , async () => {
96
- const { testAccount: sender } = fixture.context;
97
- const suggestedParams = await algodApi.transactionParams();
98
- const note = new Uint8Array(Buffer.from(' pending test' ));
90
+ test(" should get pending transaction info" , async () => {
91
+ const { testAccount: sender } = fixture.context;
92
+ const suggestedParams = await algodApi.transactionParams();
93
+ const note = new Uint8Array(Buffer.from(" pending test" ));
99
94
100
- const httpFile = createSignedTxnHttpFile(
101
- sender,
102
- { address: String(sender.addr), pubKey: sender.publicKey } ,
103
- 100000,
104
- suggestedParams,
105
- note
106
- );
95
+ const httpFile = createSignedTxnHttpFile(
96
+ sender,
97
+ { address: String(sender.addr), pubKey: sender.publicKey } ,
98
+ 100000,
99
+ suggestedParams,
100
+ note,
101
+ );
107
102
108
- const submitResult = await algodApi.rawTransaction(httpFile);
109
- expect(submitResult.txId).toBeDefined();
103
+ const submitResult = await algodApi.rawTransaction(httpFile);
104
+ expect(submitResult.txId).toBeDefined();
110
105
111
- await new Promise(resolve => setTimeout(resolve, 100));
106
+ await new Promise(( resolve) => setTimeout(resolve, 100));
112
107
113
- const pendingTxnsResult = await algodApi.getPendingTransactions(10);
114
- expect(pendingTxnsResult).toBeDefined();
108
+ const pendingTxnsResult = await algodApi.getPendingTransactions(10);
109
+ expect(pendingTxnsResult).toBeDefined();
115
110
});
116
111
117
112
// TODO: Add more tests based on other endpoints in AlgodApi related to transactions
118
- });
113
+ });
0 commit comments