Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/helpers/sorobanUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,13 @@ const convertPrimitiveField = (field: any) => {
typeHint: ["symbol"],
};
}
if (field.type === "bytes") {
const encoding = detectBytesEncoding(field.value);
return {
value: new Uint8Array(Buffer.from(field.value, encoding)),
typeHint: ["symbol", "bytes"],
};
}
return {
value: field.value,
typeHint: ["symbol", field.type],
Expand Down
32 changes: 32 additions & 0 deletions tests/unit/getScValsFromArgs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,38 @@ describe("convert js arguments to smart contract values using getScValsFromArgs"
expect(expectedResult).toEqual(scValsResult);
});

it("resolves a struct with a bytes field", () => {
const args = {
s: {
data: {
value: "deadbeef",
type: "bytes",
},
n: {
value: "7",
type: "u32",
},
},
};

const scVals: xdr.ScVal[] = [];
const scValsResult = getScValsFromArgs(args, scVals);
const expectedResult: xdr.ScVal[] = [
xdr.ScVal.scvMap([
new xdr.ScMapEntry({
key: xdr.ScVal.scvSymbol("data"),
val: xdr.ScVal.scvBytes(Buffer.from("deadbeef", "hex")),
}),
new xdr.ScMapEntry({
key: xdr.ScVal.scvSymbol("n"),
val: xdr.ScVal.scvU32(7),
}),
]),
];

expect(expectedResult).toEqual(scValsResult);
});

// Complex Enum with Struct
it("resolves a complex enum with a struct", () => {
const args = {
Expand Down