22 AccountRole ,
33 Address ,
44 Blockhash ,
5+ compileTransaction ,
56 ITransactionMessageWithFeePayer ,
67 Nonce ,
78 Rpc ,
@@ -12,9 +13,12 @@ import {
1213 SolanaError ,
1314 TransactionError ,
1415 TransactionMessage ,
15- compileTransaction ,
1616} from '@solana/kit' ;
1717import { beforeEach , describe , expect , it , Mock , vi } from 'vitest' ;
18+ import {
19+ getSetComputeUnitLimitInstruction ,
20+ MAX_COMPUTE_UNIT_LIMIT ,
21+ } from '../src' ;
1822import { estimateComputeUnitLimit } from '../src/estimateComputeLimitInternal' ;
1923
2024// Spy on the `compileTransaction` function.
@@ -114,43 +118,21 @@ describe('estimateComputeUnitLimit', () => {
114118 ...transactionMessage ,
115119 instructions : [
116120 ...transactionMessage . instructions ,
117- {
118- data :
119- // prettier-ignore
120- new Uint8Array ( [
121- 0x02 , // SetComputeUnitLimit instruction inde
122- 0xc0 , 0x5c , 0x15 , 0x00 , // 1,400,000, MAX_COMPUTE_UNITS
123- ] ) ,
124- programAddress : 'ComputeBudget111111111111111111111111111111' ,
125- } ,
121+ getSetComputeUnitLimitInstruction ( { units : MAX_COMPUTE_UNIT_LIMIT } ) ,
126122 ] ,
127123 } ) ;
128-
129- vi . doUnmock ( '@solana/kit' ) ;
130124 } ) ;
131125
132126 it ( 'replaces the existing set compute unit limit instruction when one exists' , ( ) => {
127+ const mockInstruction = {
128+ programAddress : '4Kk4nA3F2nWHCcuyT8nR6oF7HQUQHmmzAVD5k8FQPKB2' as Address ,
129+ } ;
133130 const transactionMessage = {
134131 ...mockTransactionMessage ,
135132 instructions : [
136- {
137- programAddress :
138- '4Kk4nA3F2nWHCcuyT8nR6oF7HQUQHmmzAVD5k8FQPKB2' as Address ,
139- } ,
140- {
141- data :
142- // prettier-ignore
143- new Uint8Array ( [
144- 0x02 , // SetComputeUnitLimit instruction inde
145- 0x01 , 0x02 , 0x03 , 0x04 , // ComputeUnits(u32)
146- ] ) ,
147- programAddress :
148- 'ComputeBudget111111111111111111111111111111' as Address ,
149- } ,
150- {
151- programAddress :
152- '4Kk4nA3F2nWHCcuyT8nR6oF7HQUQHmmzAVD5k8FQPKB2' as Address ,
153- } ,
133+ mockInstruction ,
134+ getSetComputeUnitLimitInstruction ( { units : 1234 } ) ,
135+ mockInstruction ,
154136 ] ,
155137 lifetimeConstraint : MOCK_BLOCKHASH_LIFETIME_CONSTRAINT ,
156138 } ;
@@ -163,12 +145,9 @@ describe('estimateComputeUnitLimit', () => {
163145 expect ( compileTransaction ) . toHaveBeenCalledWith (
164146 expect . objectContaining ( {
165147 instructions : [
166- transactionMessage . instructions [ 0 ] ,
167- {
168- ...transactionMessage . instructions [ 1 ] ,
169- data : new Uint8Array ( [ 0x02 , 0xc0 , 0x5c , 0x15 , 0x00 ] ) , // Replaced with MAX_COMPUTE_UNITS
170- } ,
171- transactionMessage . instructions [ 2 ] ,
148+ mockInstruction ,
149+ getSetComputeUnitLimitInstruction ( { units : MAX_COMPUTE_UNIT_LIMIT } ) ,
150+ mockInstruction ,
172151 ] ,
173152 } )
174153 ) ;
0 commit comments