Skip to content

Commit

Permalink
[typeTag] Add signer and &signer to typetag parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
gregnazario committed Oct 24, 2023
1 parent c903b3f commit 58dea02
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/transactions/typeTag/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
TypeTag,
TypeTagAddress,
TypeTagBool,
TypeTagSigner,
TypeTagStruct,
TypeTagU128,
TypeTagU16,
Expand Down Expand Up @@ -200,6 +201,12 @@ export function parseTypeTag(typeStr: string) {
*/
function parseTypeTagInner(str: string, types: Array<TypeTag>): TypeTag {
switch (str) {
case "&signer":
case "signer":
if (types.length > 0) {
throw new TypeTagParserError(str, TypeTagParserErrorType.UnexpectedPrimitiveTypeArguments);
}
return new TypeTagSigner();
case "bool":
if (types.length > 0) {
throw new TypeTagParserError(str, TypeTagParserErrorType.UnexpectedPrimitiveTypeArguments);
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/typeTagParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
TypeTag,
TypeTagAddress,
TypeTagBool,
TypeTagSigner,
TypeTagStruct,
TypeTagU128,
TypeTagU16,
Expand Down Expand Up @@ -101,6 +102,9 @@ describe("TypeTagParser", () => {
});

test("standard types", () => {
expect(parseTypeTag("signer")).toEqual(new TypeTagSigner());
// Technically this isn't a specific type tag, but this is a good estimation of it
expect(parseTypeTag("&signer")).toEqual(new TypeTagSigner());
expect(parseTypeTag("u8")).toEqual(new TypeTagU8());
expect(parseTypeTag("u16")).toEqual(new TypeTagU16());
expect(parseTypeTag("u32")).toEqual(new TypeTagU32());
Expand Down

0 comments on commit 58dea02

Please sign in to comment.