Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: accept lp token failed because of RangeError: Offset is outside …
…the bounds of the DataView
  • Loading branch information
wk3368 committed Feb 11, 2022
1 parent ce1bca5 commit ce2043f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/encoding/index.spec.ts
Expand Up @@ -424,6 +424,29 @@ test("encode struct type args: vote", () => {
expect(structTypeTags[1]['Struct'].type_params.length).toBe(1)
});

test("encode struct type args: lp", () => {
const strTypeArgs = ['0x4783d08fb16990bd35d83f3e23bf93b8::TokenSwap::LiquidityToken<0x00000000000000000000000000000001::STC::STC, 0xfe125d419811297dfab03c61efec0bc9::FAI::FAI>']
const structTypeTags = encodeStructTypeTags(strTypeArgs)
console.log(strTypeArgs)
console.log(JSON.stringify(structTypeTags, undefined, 2))

console.log(strTypeArgs)
const functionId = '0x1::Account::accept_token';
const args = [];
const scriptFunction = encodeScriptFunction(functionId, structTypeTags, args);
console.log(scriptFunction)

const payloadInHex = (function () {
const se = new BcsSerializer();
scriptFunction.serialize(se);
return hexlify(se.getBytes());
})();
console.log(payloadInHex)

expect(structTypeTags.length).toBe(1)
expect(structTypeTags[0]['Struct'].type_params.length).toBe(2)
});

test('decode string', () => {
const imageHex = '0x53746172636f696e47656e657369734e4654'
const imageBytes = arrayify(imageHex)
Expand Down
2 changes: 1 addition & 1 deletion src/utils/tx.ts
Expand Up @@ -199,7 +199,7 @@ function encodeStructTypeTag(
const type_params: TypeTag[] = [];
if (params.length > 0) {
params.forEach((param: string) => {
type_params.push(encodeStructTypeTag(param));
type_params.push(encodeStructTypeTag(param.trim()));
});
}

Expand Down

0 comments on commit ce2043f

Please sign in to comment.