anchor icon indicating copy to clipboard operation
anchor copied to clipboard

cpi-returns error as struct of [u16; 2]

Open yuwiggin opened this issue 2 years ago • 0 comments

I tried to test cpi-returns the callee.rs changed to

pub struct StructReturn {
      pub value: [u16; 2],
}
...
  pub fn return_struct(_ctx: Context<CpiReturn>) -> Result<StructReturn> {
      let s = StructReturn {value: [1, 2]};
      Ok(s)
  }

the cpi-return.ts changed to :

...
  it("can return a struct from a cpi", async () => {
...
    const schema = new Map([//["value", "u64"]
      [Data, { kind: "struct", fields: [["value", [2]]] }]
    ]);
...

The test can not be passed:

 1) CPI return
       can return a struct from a cpi:
     Error: Unexpected 2 bytes after deserialized data
      at Object.deserialize (node_modules/borsh/lib/index.js:430:15)
      at /home/wiggin/projs/cpi-returns/tests/cpi-return.ts:120:32
      at Generator.next (<anonymous>)
      at fulfilled (tests/cpi-return.ts:28:58)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)

Any suggestion?

yuwiggin avatar Aug 03 '22 13:08 yuwiggin