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

Dapp Bootcamp Voting: Solana Anchor-Bankerun Test fails with an uninnitized address

The recent case of the DApp Sola Blockchain test that votes DApp has faced an unexpected question that caused it to collapse. Code, namely Votul_dapp.Spec.TS from the Sola Bootcamp voting program, cannot initiate a fundamental variable.

Code:

`Typescript

Import {Accountyinfo} from ‘@solana/web3.js’;

Imported {“programmeult”, “pubertaccount}” from “@solar/angular-keygen”;

Import {

anchor

Createbenks,

initializes

} from ‘./anchor-bmerun’;

Const Crunchyaddress = ‘Tar-Crunchy-Address-Here’; // change the real address

Cons crunchycandidate = new anchorcandidate (

{Authority: “Cruunchy -authority”, name: “cruel candidate”}

);

Exported async anchorbentest () {) {)

Const banks = createbenks () waiting;

Consininfo = New Accountyinfo ({Rakid: ‘You-Cay-Here’);

Try {

Consist = wait for controx.laadaccount ();

IF (Cont.address) {

// initiate a crunchy candidate

CEP score = wait anchorbankrun (banks, account);

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

} Else {

// Manage any initialized address

Give up a new error (“the cruel address has not been found”);

}

} Catch (error) {

IF (court errors and errors.message.include (‘initiated address’)) {

Throw an error;

} Else {

console.error (error);

}

}

}

Class anchorcandidate {

builder ({authority, name}) {

This.AUTHORITY = institution;

This.Name = name;

}

Async created () {

// create a new copy of an anchor candidate

}

}

`

Question:

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

The visualization of the code reveals that the initiation of Cruunchyaddress is incomplete. The variable is declared "Construchyaddress = 'Ta-Crunchy-Address-Here; "However, it is not an attempt to determine your value or initiate before trying.

As a result, when trying to try to create a candidate for an anchorcandidate ({authority, name}), this causes an error, because Crunchyaddress has not been initiated. The code is trying to use this uneducated address later in the program.

Solution:

To solve this problem, we need to make sure that Crunchyaddress is properly initiated before using Cruunchyaddress. We can do this by adding a line to determine its value or to initiate it with the default value. Here is the updated version of the code:

Typescript

Import {Accountyinfo} from ‘@solana/web3.js’;

Imported {“programmeult”, “pubertaccount}” from “@solar/angular-keygen”;

Import {

anchor

Createbenks,

initializes

} from ‘./anchor-bmerun’;

Const Crunchyaddress = ‘0xyourcrnchyaddresrere’; // change the real address

Cons crunchycandidate = new anchorcandidate (

{Authority: “Cruunchy -authority”, name: “cruel candidate”}

);

Exported async anchorbentest () {) {)

Const banks = createbenks () waiting;

Consininfo = New Accountyinfo ({Rakid: ‘You-Cay-Here’);

Try {

Consist = wait for controx.laadaccount ();

IF (Cont.address) {

// initiate a crunchy candidate

CEP score = wait anchorbankrun (banks, account);

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

} Else {

// Manage any initialized address

Give up a new error (“the cruel address has not been found”);

}

} Catch (error) {

IF (court errors and errors.message.include (‘initiated address’)) {

Throw an error;

} Else {

console.error (error);

}

}

}

Class anchorcandidate {

builder ({authority, name}) {

This.AUTHORITY = institution;

That.

Leave a Reply

Your email address will not be published. Required fields are marked *