@@ -37,19 +37,11 @@ describe("create-and-update anchor", () => {
3737
3838 it ( "creates and updates compressed accounts atomically" , async ( ) => {
3939 const signer = new web3 . Keypair ( ) ;
40- const rpc = createRpc (
41- "http://127.0.0.1:8899" ,
42- "http://127.0.0.1:8784" ,
43- "http://127.0.0.1:3001" ,
44- {
45- commitment : "confirmed" ,
46- }
47- ) ;
40+ const rpc = createRpc ( ) ;
4841
4942 await rpc . requestAirdrop ( signer . publicKey , web3 . LAMPORTS_PER_SOL ) ;
5043 await sleep ( 2000 ) ;
5144
52- // get tree infos
5345 const stateTreeInfos = await rpc . getStateTreeInfos ( ) ;
5446 const stateTreeInfo = selectStateTreeInfo ( stateTreeInfos ) ;
5547
@@ -91,7 +83,6 @@ describe("create-and-update anchor", () => {
9183 ) ;
9284 assert . strictEqual ( decoded . message , "Initial message" ) ;
9385
94- // Derive second address
9586 const secondSeed = new TextEncoder ( ) . encode ( "second" ) ;
9687 const secondAddressSeed = deriveAddressSeedV2 ( [
9788 secondSeed ,
@@ -102,8 +93,6 @@ describe("create-and-update anchor", () => {
10293 addressTreeInfo . tree ,
10394 program . programId
10495 ) ;
105- console . log ( "secondAddress" , Array . from ( secondAddress . toBytes ( ) ) ) ;
106- console . log ( "secondAddressSeed" , Array . from ( secondAddressSeed ) ) ;
10796
10897 await createAndUpdateAccounts (
10998 rpc ,
@@ -112,7 +101,6 @@ describe("create-and-update anchor", () => {
112101 firstAccount ,
113102 secondAddress ,
114103 addressTreeInfo ,
115- "Initial message" ,
116104 "Hello from second account" ,
117105 "Updated first message"
118106 ) ;
@@ -164,9 +152,6 @@ describe("create-and-update anchor", () => {
164152 } ) ;
165153
166154 const remainingAccounts = packedAccounts . toAccountMetas ( ) . remainingAccounts ;
167- for ( const account of remainingAccounts ) {
168- console . log ( "remainingAccount" , account . pubkey . toBase58 ( ) ) ;
169- }
170155 const tx = await program . methods
171156 . createCompressedAccount (
172157 proof ,
@@ -185,8 +170,7 @@ describe("create-and-update anchor", () => {
185170 const recentBlockhash = ( await rpc . getRecentBlockhash ( ) ) . blockhash ;
186171
187172 const signedTx = buildAndSignTx ( tx . instructions , signer , recentBlockhash ) ;
188- const sig = await sendAndConfirmTx ( rpc , signedTx , { skipPreflight : true } ) ;
189- console . log ( "createCompressedAccount sig" , sig ) ;
173+ const sig = await sendAndConfirmTx ( rpc , signedTx ) ;
190174 return sig ;
191175 }
192176
@@ -197,7 +181,6 @@ describe("create-and-update anchor", () => {
197181 existingAccount : CompressedAccountWithMerkleContext ,
198182 newAddress : anchor . web3 . PublicKey ,
199183 addressTreeInfo : TreeInfo ,
200- existingMessage : string ,
201184 newAccountMessage : string ,
202185 updatedMessage : string
203186 ) {
@@ -223,35 +206,38 @@ describe("create-and-update anchor", () => {
223206 ]
224207 ) ;
225208
226- console . log ( "existing hash" , existingAccount . hash . toArray ( ) ) ;
209+ const coder = new anchor . BorshCoder ( program . idl ) ;
210+ const currentAccountData = coder . types . decode (
211+ "dataAccount" ,
212+ existingAccount . data . data
213+ ) ;
227214
228215 const config = SystemAccountMetaConfig . new ( program . programId ) ;
229216 const packedAccounts = PackedAccounts . newWithSystemAccountsV2 ( config ) ;
230217
231- const existingQueueIndex = packedAccounts . insertOrGet (
232- existingAccount . treeInfo . queue
233- ) ;
234- const existingMerkleTreeIndex = packedAccounts . insertOrGet (
235- existingAccount . treeInfo . tree
236- ) ;
237- const outputStateTreeIndex = packedAccounts . insertOrGet (
238- existingAccount . treeInfo . queue
239- ) ;
240-
241218 const existingAccountMeta = {
242219 treeInfo : {
243- merkleTreePubkeyIndex : existingMerkleTreeIndex ,
244- queuePubkeyIndex : existingQueueIndex ,
245- leafIndex : existingAccount . leafIndex ,
246- proveByIndex : false ,
247220 rootIndex : proofRpcResult . rootIndices [ 0 ] ,
221+ // Note: set this to true for local testing.
222+ proveByIndex : true ,
223+ merkleTreePubkeyIndex : packedAccounts . insertOrGet (
224+ existingAccount . treeInfo . tree
225+ ) ,
226+ queuePubkeyIndex : packedAccounts . insertOrGet (
227+ existingAccount . treeInfo . queue
228+ ) ,
229+ leafIndex : existingAccount . leafIndex ,
248230 } ,
249231 address : existingAccount . address ,
250- outputStateTreeIndex,
232+ outputStateTreeIndex : packedAccounts . insertOrGet (
233+ existingAccount . treeInfo . queue
234+ ) ,
251235 } ;
252236
237+ // for new account's address
253238 const addressQueueIndex = packedAccounts . insertOrGet ( addressTreeInfo . queue ) ;
254239 const addressTreeIndex = packedAccounts . insertOrGet ( addressTreeInfo . tree ) ;
240+
255241 const packedAddressTreeInfo : PackedAddressTreeInfo = {
256242 rootIndex : proofRpcResult . rootIndices [ 1 ] ,
257243 addressMerkleTreePubkeyIndex : addressTreeIndex ,
@@ -266,15 +252,13 @@ describe("create-and-update anchor", () => {
266252 } ) ;
267253
268254 const remainingAccounts = packedAccounts . toAccountMetas ( ) . remainingAccounts ;
269- for ( const account of remainingAccounts ) {
270- console . log ( "remainingAccount" , account . pubkey . toBase58 ( ) ) ;
271- }
255+
272256 const tx = await program . methods
273257 . createAndUpdate (
274258 proof ,
275259 {
276260 accountMeta : existingAccountMeta ,
277- message : existingMessage ,
261+ message : currentAccountData . message ,
278262 updateMessage : updatedMessage ,
279263 } ,
280264 {
@@ -292,8 +276,7 @@ describe("create-and-update anchor", () => {
292276
293277 const recentBlockhash = ( await rpc . getRecentBlockhash ( ) ) . blockhash ;
294278 const signedTx = buildAndSignTx ( tx . instructions , signer , recentBlockhash ) ;
295- const sig = await sendAndConfirmTx ( rpc , signedTx , { skipPreflight : false } ) ;
296- console . log ( "createAndUpdate sig" , sig ) ;
279+ const sig = await sendAndConfirmTx ( rpc , signedTx ) ;
297280 return sig ;
298281 }
299282} ) ;
0 commit comments