Skip to content

Commit

Permalink
clean up typetag snake case to camelcase
Browse files Browse the repository at this point in the history
  • Loading branch information
Jin authored and gregnazario committed Nov 2, 2023
1 parent 2bfef08 commit a87f550
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/transactions/transactionBuilder/remoteAbi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ function parseArg(
return new MoveOption<U8>(null);
}

return new MoveOption(parseArg(arg, param.value.type_args[0], position, genericTypeParams));
return new MoveOption(parseArg(arg, param.value.typeArgs[0], position, genericTypeParams));
}

throw new Error(`Unsupported struct input type for argument ${position}, type '${param.toString()}'`);
Expand Down
20 changes: 10 additions & 10 deletions src/transactions/typeTag/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,11 @@ export class TypeTagStruct extends TypeTag {
toString(): `0x${string}::${string}::${string}` {
// Collect type args and add it if there are any
let typePredicate = "";
if (this.value.type_args.length > 0) {
typePredicate = `<${this.value.type_args.map((typeArg) => typeArg.toString()).join(", ")}>`;
if (this.value.typeArgs.length > 0) {
typePredicate = `<${this.value.typeArgs.map((typeArg) => typeArg.toString()).join(", ")}>`;
}

return `${this.value.address.toString()}::${this.value.module_name.identifier}::${
return `${this.value.address.toString()}::${this.value.moduleName.identifier}::${
this.value.name.identifier
}${typePredicate}`;
}
Expand All @@ -316,7 +316,7 @@ export class TypeTagStruct extends TypeTag {

isTypeTag(address: AccountAddress, moduleName: string, structName: string): boolean {
return (
this.value.module_name.identifier === moduleName &&
this.value.moduleName.identifier === moduleName &&
this.value.name.identifier === structName &&
this.value.address.equals(address)
);
Expand All @@ -338,25 +338,25 @@ export class TypeTagStruct extends TypeTag {
export class StructTag extends Serializable {
public readonly address: AccountAddress;

public readonly module_name: Identifier;
public readonly moduleName: Identifier;

public readonly name: Identifier;

public readonly type_args: Array<TypeTag>;
public readonly typeArgs: Array<TypeTag>;

constructor(address: AccountAddress, module_name: Identifier, name: Identifier, type_args: Array<TypeTag>) {
super();
this.address = address;
this.module_name = module_name;
this.moduleName = module_name;
this.name = name;
this.type_args = type_args;
this.typeArgs = type_args;
}

serialize(serializer: Serializer): void {
serializer.serialize(this.address);
serializer.serialize(this.module_name);
serializer.serialize(this.moduleName);
serializer.serialize(this.name);
serializer.serializeVector(this.type_args);
serializer.serializeVector(this.typeArgs);
}

static deserialize(deserializer: Deserializer): StructTag {
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/api/coin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("coin", () => {
const rawTransaction = RawTransaction.deserialize(txnDeserializer);
const typeArgs = (rawTransaction.payload as TransactionPayloadEntryFunction).entryFunction.type_args;
expect((typeArgs[0] as TypeTagStruct).value.address.toString()).toBe("0x1");
expect((typeArgs[0] as TypeTagStruct).value.module_name.identifier).toBe("aptos_coin");
expect((typeArgs[0] as TypeTagStruct).value.moduleName.identifier).toBe("aptos_coin");
expect((typeArgs[0] as TypeTagStruct).value.name.identifier).toBe("AptosCoin");
});

Expand All @@ -43,7 +43,7 @@ describe("coin", () => {
const rawTransaction = RawTransaction.deserialize(txnDeserializer);
const typeArgs = (rawTransaction.payload as TransactionPayloadEntryFunction).entryFunction.type_args;
expect((typeArgs[0] as TypeTagStruct).value.address.toString()).toBe("0x1");
expect((typeArgs[0] as TypeTagStruct).value.module_name.identifier).toBe("my_coin");
expect((typeArgs[0] as TypeTagStruct).value.moduleName.identifier).toBe("my_coin");
expect((typeArgs[0] as TypeTagStruct).value.name.identifier).toBe("type");
});

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/typeTag.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ describe("Deserialize TypeTags", () => {
expect(deserialized).toBeInstanceOf(TypeTagStruct);
expect(deserialized.value).toBeInstanceOf(StructTag);
expect(deserialized.value.address.toString()).toEqual(expectedTypeTag.address);
expect(deserialized.value.module_name.identifier).toEqual("some_module");
expect(deserialized.value.moduleName.identifier).toEqual("some_module");
expect(deserialized.value.name.identifier).toEqual("SomeResource");
expect(deserialized.value.type_args.length).toEqual(0);
expect(deserialized.value.typeArgs.length).toEqual(0);
});
});

0 comments on commit a87f550

Please sign in to comment.