1

I am creating a PDA account that stores a string and a vector. Inside this vector, there is another vector. This is the structure of my account:

#[account]
pub struct Monster {
    
    pub seed : String,
    pub evolutions: Vec<Evolution>,
}

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug)]
pub struct Evolution {

    pub possible_evolution: String,
    pub requirements: Vec<Requirement>,

}

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug)]
pub struct Requirement {

    pub key_requirement: String,
    pub value_requirement: i16,

} 

But when i output my code after run anchor test, it show something like this. It seems that the second vector has not been properly serialized:

{
  seed: 'ramdomName',
  evolutions: [
    { possibleEvolution: 'evolution1', requirements: [Array] },
    { possibleEvolution: 'evolution2', requirements: [Array] }
  ]
}

What could be the problem?

I'm passing the data in my test in this way:

    const evolutions = [
      { possibleEvolution: 'evolution1', 
        requirements:[
          {keyRequirement:'gender', valueRequirement: 100},
          {keyRequirement:'attack', valueRequirement:200}
        ] 
      },

      { possibleEvolution: 'evolution2', 
        requirements:[
          {keyRequirement:'gender', valueRequirement:100},
        ]
      },
    ];

1 Answer 1

1

Everything is fine. My bad. I used the JSON.stringify method in my test to convert the account object to a string with 2 spaces of indentation for each level of nesting, and that way it was displayed properly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.