stellar / js-stellar-sdk

Main Stellar client library for the JavaScript language.
https://stellar.github.io/js-stellar-sdk/
Apache License 2.0
615 stars 296 forks source link

TypeError: Bad union switch: 1 #958

Closed kalepail closed 2 months ago

kalepail commented 2 months ago

Describe the bug Trying to use the getLedgerEntries on futurenet with the latest sdk.

const wasm_hash = "390c0dc0c56b66db3847d1ab75d8bfda164bda5a7032a049921f5529202ddd95"

const lk = xdr.LedgerKey.contractCode(
    new xdr.LedgerKeyContractCode({
        hash: Buffer.from(wasm_hash, 'hex'),
    })
)

await rpc.getLedgerEntries(lk)

What version are you on? "@stellar/stellar-sdk": "^12.0.0-rc.1",

Error

1744 |       return member;
1745 |     }
1746 |     if (this._defaultArm) {
1747 |       return this._defaultArm;
1748 |     }
1749 |     throw new TypeError(`Bad union switch: ${aSwitch}`);
                 ^
TypeError: Bad union switch: 1
      at armForSwitch (/Users/tylervanderhoeven/Desktop/Web/Colorglyph-2.0/colorglyph-soroban/bun_tests/node_modules/@stellar/js-xdr/lib/xdr.js:1749:11)
      at read (/Users/tylervanderhoeven/Desktop/Web/Colorglyph-2.0/colorglyph-soroban/bun_tests/node_modules/@stellar/js-xdr/lib/xdr.js:1763:17)
      at read (/Users/tylervanderhoeven/Desktop/Web/Colorglyph-2.0/colorglyph-soroban/bun_tests/node_modules/@stellar/js-xdr/lib/xdr.js:1568:31)
      at read (/Users/tylervanderhoeven/Desktop/Web/Colorglyph-2.0/colorglyph-soroban/bun_tests/node_modules/@stellar/js-xdr/lib/xdr.js:1767:15)
      at fromXDR (/Users/tylervanderhoeven/Desktop/Web/Colorglyph-2.0/colorglyph-soroban/bun_tests/node_modules/@stellar/js-xdr/lib/xdr.js:2172:20)
      at /Users/tylervanderhoeven/Desktop/Web/Colorglyph-2.0/colorglyph-soroban/bun_tests/node_modules/@stellar/stellar-sdk/lib/soroban/parsers.js:63:14
      at map (:1:21)
      at parseRawLedgerEntries (/Users/tylervanderhoeven/Desktop/Web/Colorglyph-2.0/colorglyph-soroban/bun_tests/node_modules/@stellar/stellar-sdk/lib/soroban/parsers.js:56:5)

This works fine on testnet and mainnet.

leighmcculloch commented 2 months ago

To help with debugging, this is the XDR for the ledger key:

$ echo '{"contract_code":{"hash":"390c0dc0c56b66db3847d1ab75d8bfda164bda5a7032a049921f5529202ddd95"}}' \
    | stellar-xdr encode --type LedgerKey
AAAABzkMDcDFa2bbOEfRq3XYv9oWS9pacDKgSZIfVSkgLd2V
Shaptic commented 2 months ago

Closed by rc.2, thanks for the report!