diff --git a/traits.tests.ts b/traits.tests.ts index e402984..de68653 100644 --- a/traits.tests.ts +++ b/traits.tests.ts @@ -3,7 +3,6 @@ import { IContractAST, } from "@hirosystems/clarinet-sdk-wasm"; import { initSimnet } from "@hirosystems/clarinet-sdk"; -import { readFileSync } from "fs"; import { resolve } from "path"; import { buildTraitReferenceMap, @@ -107,6 +106,68 @@ describe("Trait reference processing", () => { expect(traitReferenceMap).toEqual(expectedTraitReferenceMap); }); + it("correctly builds the trait reference map for a response ok branch nested trait", () => { + // Arrange + const allFunctionsInterfaces = testInputs.responseOkTraitParameter + .functionsInterfaces as ContractInterfaceFunction[]; + + const expectedTraitReferenceMap = new Map( + Object.entries({ + "test-trait": { + "resp-trait-param": { response: { ok: "trait_reference" } }, + }, + }) + ); + + // Act + const traitReferenceMap = buildTraitReferenceMap(allFunctionsInterfaces); + + // Assert + expect(traitReferenceMap).toEqual(expectedTraitReferenceMap); + }); + + it("correctly builds the trait reference map for a response error branch nested trait", () => { + // Arrange + const allFunctionsInterfaces = testInputs.responseErrTraitParameter + .functionsInterfaces as ContractInterfaceFunction[]; + + const expectedTraitReferenceMap = new Map( + Object.entries({ + "test-trait": { + "resp-trait-param": { response: { error: "trait_reference" } }, + }, + }) + ); + + // Act + const traitReferenceMap = buildTraitReferenceMap(allFunctionsInterfaces); + + // Assert + expect(traitReferenceMap).toEqual(expectedTraitReferenceMap); + }); + + it("correctly builds the trait reference map for a response both branches nested trait", () => { + // Arrange + const allFunctionsInterfaces = testInputs.responseBothTraitParameter + .functionsInterfaces as ContractInterfaceFunction[]; + + const expectedTraitReferenceMap = new Map( + Object.entries({ + "test-trait": { + "resp-trait-param": { + response: { ok: "trait_reference", error: "trait_reference" }, + }, + }, + }) + ); + + // Act + const traitReferenceMap = buildTraitReferenceMap(allFunctionsInterfaces); + + // Assert + expect(traitReferenceMap).toEqual(expectedTraitReferenceMap); + }); + it("correctly enriches interface with trait reference data for a direct trait that is the first parameter", () => { // Arrange const targetContractId = "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.trait"; @@ -605,172 +666,377 @@ describe("Trait reference processing", () => { expect(enrichedTestFunctionsInterfacesMap).toEqual(expected); }); - it("correctly retrieves the contracts implementing a trait from the Clarinet project", async () => { + it("correctly enriches interface with trait reference data for a response ok branch nested trait", () => { // Arrange - const simnet = await initSimnet( - resolve(__dirname, "example", "Clarinet.toml") - ); - - const traitData = { - name: "ft-trait", - import: { - Imported: { - name: "sip-010-trait", - contract_identifier: { - name: "sip-010-trait-ft-standard", - issuer: [ - 22, - [ - 9, 159, 184, 137, 38, 216, 47, 48, 178, 244, 14, 175, 62, 228, - 35, 203, 114, 91, 219, 59, - ], - ], - }, - }, - }, - }; + const targetContractId = "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.trait"; - const expected = ["SP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.ststx-token"]; + const allFunctionsInterfaces = ( + testInputs.responseOkTraitParameter + .functionsInterfaces as ContractInterfaceFunction[] + ).filter((f: any) => f.name !== "update-context"); - // Act - const traitImplementations = getContractIdsImplementingTrait( - traitData, - simnet - ); + const traitReferenceMap = buildTraitReferenceMap(allFunctionsInterfaces); - // Assert - expect(traitImplementations).toEqual(expected); - }); -}); + const ast = testInputs.responseOkTraitParameter.ast as any as IContractAST; -describe("Trait reference detection", () => { - it("returns false when no arguments contain a trait reference", async () => { - // Arrange - const noTraitFunction = { - name: "function-without-traits", - access: "public", - args: [ - { name: "arg1", type: "uint128" }, - { name: "arg2", type: { buffer: { length: 10 } } }, - { name: "arg3", type: { "string-ascii": { length: 20 } } }, - { name: "arg4", type: "principal" }, - { name: "arg5", type: "bool" }, - { name: "arg6", type: "int128" }, - ], - outputs: { - type: { - response: { - ok: "bool", - error: "uint128", + const expected = new Map( + Object.entries({ + [targetContractId]: [ + { + name: "function", + access: "public", + args: [], + outputs: { + type: { + response: { + error: "none", + ok: "bool", + }, + }, + }, }, - }, - }, - } as ContractInterfaceFunction; - - // Act - const result = isTraitReferenceFunction(noTraitFunction); - - // Assert - expect(result).toBe(false); - }); - - it("returns true when an argument contains a trait reference", async () => { - // Arrange - const traitFunction = { - name: "function-with-traits", - access: "public", - args: [ - { name: "arg1", type: "trait_reference" }, - { name: "arg2", type: "uint128" }, - ], - outputs: { - type: { - response: { - ok: "bool", - error: "uint128", + { + name: "test-no-trait", + access: "public", + args: [], + outputs: { + type: { + response: { + error: "none", + ok: "bool", + }, + }, + }, }, - }, - }, - } as ContractInterfaceFunction; + { + name: "test-trait", + access: "public", + args: [ + { + name: "resp-trait-param", + type: { + response: { + ok: { + trait_reference: { + name: "ft-trait", + import: { + Imported: { + name: "sip-010-trait", + contract_identifier: { + name: "sip-010-trait-ft-standard", + issuer: [ + 22, + [ + 9, 159, 184, 137, 38, 216, 47, 48, 178, 244, + 14, 175, 62, 228, 35, 203, 114, 91, 219, 59, + ], + ], + }, + }, + }, + }, + }, + error: "uint128", + }, + }, + }, + ], + outputs: { + type: { + response: { + ok: "bool", + error: "none", + }, + }, + }, + }, + ], + }) + ); // Act - const result = isTraitReferenceFunction(traitFunction); + const enrichedTestFunctionsInterfacesMap = enrichInterfaceWithTraitData( + ast, + traitReferenceMap, + allFunctionsInterfaces, + targetContractId + ); // Assert - expect(result).toBe(true); + expect(enrichedTestFunctionsInterfacesMap).toEqual(expected); }); - it("returns false for a list argument without traits", async () => { + it("correctly enriches interface with trait reference data for a response error branch nested trait", () => { // Arrange - const listFunction = { - name: "list-without-traits", - access: "public", - args: [ - { - name: "listArg", - type: { list: { type: "uint128", length: 5 } }, - }, - ], - outputs: { - type: { - response: { - ok: "bool", - error: "uint128", - }, - }, - }, - } as ContractInterfaceFunction; + const targetContractId = "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.trait"; - // Act - const result = isTraitReferenceFunction(listFunction); + const allFunctionsInterfaces = ( + testInputs.responseErrTraitParameter + .functionsInterfaces as ContractInterfaceFunction[] + ).filter((f: any) => f.name !== "update-context"); - // Assert - expect(result).toBe(false); - }); + const traitReferenceMap = buildTraitReferenceMap(allFunctionsInterfaces); - it("returns true for a list argument with traits", async () => { - // Arrange - const listWithTraitFunction = { - name: "list-with-traits", - access: "public", - args: [ - { - name: "listArg", - type: { list: { type: "trait_reference", length: 5 } }, - }, - ], - outputs: { - type: { - response: { - ok: "bool", - error: "uint128", + const ast = testInputs.responseErrTraitParameter.ast as any as IContractAST; + + const expected = new Map( + Object.entries({ + [targetContractId]: [ + { + name: "function", + access: "public", + args: [], + outputs: { + type: { + response: { + error: "none", + ok: "bool", + }, + }, + }, + }, + { + name: "test-no-trait", + access: "public", + args: [], + outputs: { + type: { + response: { + error: "none", + ok: "bool", + }, + }, + }, + }, + { + name: "test-trait", + access: "public", + args: [ + { + name: "resp-trait-param", + type: { + response: { + ok: "uint128", + error: { + trait_reference: { + name: "ft-trait", + import: { + Imported: { + name: "sip-010-trait", + contract_identifier: { + name: "sip-010-trait-ft-standard", + issuer: [ + 22, + [ + 9, 159, 184, 137, 38, 216, 47, 48, 178, 244, + 14, 175, 62, 228, 35, 203, 114, 91, 219, 59, + ], + ], + }, + }, + }, + }, + }, + }, + }, + }, + ], + outputs: { + type: { + response: { + ok: "bool", + error: "none", + }, + }, + }, + }, + ], + }) + ); + + // Act + const enrichedTestFunctionsInterfacesMap = enrichInterfaceWithTraitData( + ast, + traitReferenceMap, + allFunctionsInterfaces, + targetContractId + ); + + // Assert + expect(enrichedTestFunctionsInterfacesMap).toEqual(expected); + }); + + it("correctly enriches interface with trait reference data for a response both branches nested trait", () => { + // Arrange + const targetContractId = "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.trait"; + + const allFunctionsInterfaces = ( + testInputs.responseBothTraitParameter + .functionsInterfaces as ContractInterfaceFunction[] + ).filter((f: any) => f.name !== "update-context"); + + const traitReferenceMap = buildTraitReferenceMap(allFunctionsInterfaces); + + const ast = testInputs.responseBothTraitParameter + .ast as any as IContractAST; + + const expected = new Map( + Object.entries({ + [targetContractId]: [ + { + name: "function", + access: "public", + args: [], + outputs: { + type: { + response: { + error: "none", + ok: "bool", + }, + }, + }, + }, + { + name: "test-no-trait", + access: "public", + args: [], + outputs: { + type: { + response: { + error: "none", + ok: "bool", + }, + }, + }, + }, + { + name: "test-trait", + access: "public", + args: [ + { + name: "resp-trait-param", + type: { + response: { + ok: { + trait_reference: { + name: "ft-trait", + import: { + Imported: { + name: "sip-010-trait", + contract_identifier: { + name: "sip-010-trait-ft-standard", + issuer: [ + 22, + [ + 9, 159, 184, 137, 38, 216, 47, 48, 178, 244, + 14, 175, 62, 228, 35, 203, 114, 91, 219, 59, + ], + ], + }, + }, + }, + }, + }, + error: { + trait_reference: { + name: "ft-trait", + import: { + Imported: { + name: "sip-010-trait", + contract_identifier: { + name: "sip-010-trait-ft-standard", + issuer: [ + 22, + [ + 9, 159, 184, 137, 38, 216, 47, 48, 178, 244, + 14, 175, 62, 228, 35, 203, 114, 91, 219, 59, + ], + ], + }, + }, + }, + }, + }, + }, + }, + }, + ], + outputs: { + type: { + response: { + ok: "bool", + error: "none", + }, + }, + }, + }, + ], + }) + ); + + // Act + const enrichedTestFunctionsInterfacesMap = enrichInterfaceWithTraitData( + ast, + traitReferenceMap, + allFunctionsInterfaces, + targetContractId + ); + + // Assert + expect(enrichedTestFunctionsInterfacesMap).toEqual(expected); + }); + + it("correctly retrieves the contracts implementing a trait from the Clarinet project", async () => { + // Arrange + const simnet = await initSimnet( + resolve(__dirname, "example", "Clarinet.toml") + ); + + const traitData = { + name: "ft-trait", + import: { + Imported: { + name: "sip-010-trait", + contract_identifier: { + name: "sip-010-trait-ft-standard", + issuer: [ + 22, + [ + 9, 159, 184, 137, 38, 216, 47, 48, 178, 244, 14, 175, 62, 228, + 35, 203, 114, 91, 219, 59, + ], + ], }, }, }, - } as ContractInterfaceFunction; + }; + + const expected = ["SP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.ststx-token"]; // Act - const result = isTraitReferenceFunction(listWithTraitFunction); + const traitImplementations = getContractIdsImplementingTrait( + traitData, + simnet + ); // Assert - expect(result).toBe(true); + expect(traitImplementations).toEqual(expected); }); +}); - it("returns false for a tuple argument without traits", async () => { +describe("Trait reference detection", () => { + it("returns false when no arguments contain a trait reference", async () => { // Arrange - const tupleFunction = { - name: "tuple-without-traits", + const noTraitFunction = { + name: "function-without-traits", access: "public", args: [ - { - name: "tupleArg", - type: { - tuple: [ - { name: "field1", type: "uint128" }, - { name: "field2", type: { buffer: { length: 10 } } }, - ], - }, - }, + { name: "arg1", type: "uint128" }, + { name: "arg2", type: { buffer: { length: 10 } } }, + { name: "arg3", type: { "string-ascii": { length: 20 } } }, + { name: "arg4", type: "principal" }, + { name: "arg5", type: "bool" }, + { name: "arg6", type: "int128" }, ], outputs: { type: { @@ -783,13 +1049,128 @@ describe("Trait reference detection", () => { } as ContractInterfaceFunction; // Act - const result = isTraitReferenceFunction(tupleFunction); + const result = isTraitReferenceFunction(noTraitFunction); // Assert expect(result).toBe(false); }); - it("returns true for a tuple argument with traits", async () => { + it("returns true when an argument contains a trait reference", async () => { + // Arrange + const traitFunction = { + name: "function-with-traits", + access: "public", + args: [ + { name: "arg1", type: "trait_reference" }, + { name: "arg2", type: "uint128" }, + ], + outputs: { + type: { + response: { + ok: "bool", + error: "uint128", + }, + }, + }, + } as ContractInterfaceFunction; + + // Act + const result = isTraitReferenceFunction(traitFunction); + + // Assert + expect(result).toBe(true); + }); + + it("returns false for a list argument without traits", async () => { + // Arrange + const listFunction = { + name: "list-without-traits", + access: "public", + args: [ + { + name: "listArg", + type: { list: { type: "uint128", length: 5 } }, + }, + ], + outputs: { + type: { + response: { + ok: "bool", + error: "uint128", + }, + }, + }, + } as ContractInterfaceFunction; + + // Act + const result = isTraitReferenceFunction(listFunction); + + // Assert + expect(result).toBe(false); + }); + + it("returns true for a list argument with traits", async () => { + // Arrange + const listWithTraitFunction = { + name: "list-with-traits", + access: "public", + args: [ + { + name: "listArg", + type: { list: { type: "trait_reference", length: 5 } }, + }, + ], + outputs: { + type: { + response: { + ok: "bool", + error: "uint128", + }, + }, + }, + } as ContractInterfaceFunction; + + // Act + const result = isTraitReferenceFunction(listWithTraitFunction); + + // Assert + expect(result).toBe(true); + }); + + it("returns false for a tuple argument without traits", async () => { + // Arrange + const tupleFunction = { + name: "tuple-without-traits", + access: "public", + args: [ + { + name: "tupleArg", + type: { + tuple: [ + { name: "field1", type: "uint128" }, + { name: "field2", type: { buffer: { length: 10 } } }, + ], + }, + }, + ], + outputs: { + type: { + response: { + ok: "bool", + error: "uint128", + }, + }, + }, + } as ContractInterfaceFunction; + + // Act + const result = isTraitReferenceFunction(tupleFunction); + + // Assert + expect(result).toBe(false); + }); + + it("returns true for a tuple argument with traits", async () => { // Arrange const tupleWithTraitFunction = { name: "tuple-with-traits", @@ -887,89 +1268,3069 @@ describe("Trait reference detection", () => { ok: "bool", error: "uint128", }, - }, - }, - } as ContractInterfaceFunction; - - // Act - const result = isTraitReferenceFunction(responseFunction); - - // Assert - expect(result).toBe(false); - }); - - it("returns true for a response argument with traits", async () => { - // Arrange - const responseWithTraitFunction = { - name: "response-with-traits", - access: "public", - args: [ - { - name: "responseArg", - type: { - response: { ok: "trait_reference", error: "uint128" }, + }, + }, + } as ContractInterfaceFunction; + + // Act + const result = isTraitReferenceFunction(responseFunction); + + // Assert + expect(result).toBe(false); + }); + + it("returns true for a response argument with traits", async () => { + // Arrange + const responseWithTraitFunction = { + name: "response-with-traits", + access: "public", + args: [ + { + name: "responseArg", + type: { + response: { ok: "trait_reference", error: "uint128" }, + }, + }, + ], + outputs: { + type: { + response: { + ok: "bool", + error: "uint128", + }, + }, + }, + } as ContractInterfaceFunction; + + // Act + const result = isTraitReferenceFunction(responseWithTraitFunction); + + // Assert + expect(result).toBe(true); + }); + + it("returns false for unexpected argument types", async () => { + // Arrange + const unexpectedTypeFunction = { + name: "unexpected-type-function", + access: "public", + args: [{ name: "unexpectedArg", type: "custom_type" as any }], + outputs: { + type: { + response: { + ok: "bool", + error: "uint128", + }, + }, + }, + } as ContractInterfaceFunction; + + // Act + const result = isTraitReferenceFunction(unexpectedTypeFunction); + + // Assert + expect(result).toBe(false); + }); + + it("returns false for an argument with an unrecognized complex type", async () => { + // Arrange + const unrecognizedTypeFunction = { + name: "unrecognized-type-function", + access: "public", + args: [{ name: "unknownArg", type: { unknown: "some_value" } as any }], + outputs: { type: "bool" }, + } as ContractInterfaceFunction; + + // Act + const result = isTraitReferenceFunction(unrecognizedTypeFunction); + + // Assert + expect(result).toBe(false); + }); +}); + +const testInputs = { + directTrait1stParameter: { + functionsInterfaces: [ + { + name: "function", + access: "public", + args: [], + outputs: { + type: { + response: { + ok: "bool", + error: "none", + }, + }, + }, + }, + { + name: "test-no-trait", + access: "public", + args: [], + outputs: { + type: { + response: { + ok: "bool", + error: "none", + }, + }, + }, + }, + { + name: "test-trait", + access: "public", + args: [ + { + name: "token", + type: "trait_reference", + }, + ], + outputs: { + type: { + response: { + ok: "bool", + error: "none", + }, + }, + }, + }, + { + name: "update-context", + access: "public", + args: [ + { + name: "function-name", + type: { + "string-ascii": { + length: 100, + }, + }, + }, + { + name: "called", + type: "uint128", + }, + ], + outputs: { + type: { + response: { + ok: "bool", + error: "none", + }, + }, + }, + }, + ], + ast: { + contract_identifier: { + issuer: [ + 26, + [ + 109, 120, 222, 123, 6, 37, 223, 191, 193, 108, 58, 138, 87, 53, 246, + 220, 61, 195, 242, 206, + ], + ], + name: "trait", + }, + pre_expressions: [], + expressions: [ + { + expr: { + List: [ + { + expr: { + Atom: "use-trait", + }, + id: 2, + span: { + start_line: 1, + start_column: 2, + end_line: 1, + end_column: 10, + }, + }, + { + expr: { + Atom: "ft-trait", + }, + id: 3, + span: { + start_line: 1, + start_column: 12, + end_line: 1, + end_column: 19, + }, + }, + { + expr: { + Field: { + name: "sip-010-trait", + contract_identifier: { + issuer: [ + 22, + [ + 9, 159, 184, 137, 38, 216, 47, 48, 178, 244, 14, 175, + 62, 228, 35, 203, 114, 91, 219, 59, + ], + ], + name: "sip-010-trait-ft-standard", + }, + }, + }, + id: 4, + span: { + start_line: 1, + start_column: 21, + end_line: 1, + end_column: 101, + }, + }, + ], + }, + id: 1, + span: { + start_line: 1, + start_column: 1, + end_line: 1, + end_column: 102, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "define-public", + }, + id: 6, + span: { + start_line: 3, + start_column: 2, + end_line: 3, + end_column: 14, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "trait-transfer-function", + }, + id: 8, + span: { + start_line: 3, + start_column: 17, + end_line: 3, + end_column: 39, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "token", + }, + id: 10, + span: { + start_line: 3, + start_column: 42, + end_line: 3, + end_column: 46, + }, + }, + { + expr: { + TraitReference: [ + "ft-trait", + { + Imported: { + name: "sip-010-trait", + contract_identifier: { + issuer: [ + 22, + [ + 9, 159, 184, 137, 38, 216, 47, 48, + 178, 244, 14, 175, 62, 228, 35, 203, + 114, 91, 219, 59, + ], + ], + name: "sip-010-trait-ft-standard", + }, + }, + }, + ], + }, + id: 11, + span: { + start_line: 3, + start_column: 48, + end_line: 3, + end_column: 57, + }, + }, + ], + }, + id: 9, + span: { + start_line: 3, + start_column: 41, + end_line: 3, + end_column: 58, + }, + }, + ], + }, + id: 7, + span: { + start_line: 3, + start_column: 16, + end_line: 3, + end_column: 59, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "ok", + }, + id: 13, + span: { + start_line: 4, + start_column: 4, + end_line: 4, + end_column: 5, + }, + }, + { + expr: { + Atom: "true", + }, + id: 14, + span: { + start_line: 4, + start_column: 7, + end_line: 4, + end_column: 10, + }, + }, + ], + }, + id: 12, + span: { + start_line: 4, + start_column: 3, + end_line: 4, + end_column: 11, + }, + }, + ], + }, + id: 5, + span: { + start_line: 3, + start_column: 1, + end_line: 5, + end_column: 1, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "define-map", + }, + id: 16, + span: { + start_line: 8, + start_column: 2, + end_line: 8, + end_column: 11, + }, + }, + { + expr: { + Atom: "context", + }, + id: 17, + span: { + start_line: 8, + start_column: 13, + end_line: 8, + end_column: 19, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "string-ascii", + }, + id: 19, + span: { + start_line: 8, + start_column: 22, + end_line: 8, + end_column: 33, + }, + }, + { + expr: { + LiteralValue: { + Int: "100", + }, + }, + id: 20, + span: { + start_line: 8, + start_column: 35, + end_line: 8, + end_column: 37, + }, + }, + ], + }, + id: 18, + span: { + start_line: 8, + start_column: 21, + end_line: 8, + end_column: 38, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "tuple", + }, + id: 22, + span: { + start_line: 0, + start_column: 0, + end_line: 0, + end_column: 0, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "called", + }, + id: 24, + span: { + start_line: 9, + start_column: 5, + end_line: 9, + end_column: 10, + }, + }, + { + expr: { + Atom: "uint", + }, + id: 25, + span: { + start_line: 9, + start_column: 13, + end_line: 9, + end_column: 16, + }, + post_comments: [ + [ + "other data", + { + start_line: 10, + start_column: 5, + end_line: 10, + end_column: 17, + }, + ], + ], + }, + ], + }, + id: 23, + span: { + start_line: 9, + start_column: 5, + end_line: 9, + end_column: 16, + }, + }, + ], + }, + id: 21, + span: { + start_line: 8, + start_column: 40, + end_line: 11, + end_column: 3, + }, + }, + ], + }, + id: 15, + span: { + start_line: 8, + start_column: 1, + end_line: 11, + end_column: 4, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "define-public", + }, + id: 27, + span: { + start_line: 13, + start_column: 4, + end_line: 13, + end_column: 16, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "update-context", + }, + id: 29, + span: { + start_line: 13, + start_column: 19, + end_line: 13, + end_column: 32, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "function-name", + }, + id: 31, + span: { + start_line: 13, + start_column: 35, + end_line: 13, + end_column: 47, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "string-ascii", + }, + id: 33, + span: { + start_line: 13, + start_column: 50, + end_line: 13, + end_column: 61, + }, + }, + { + expr: { + LiteralValue: { + Int: "100", + }, + }, + id: 34, + span: { + start_line: 13, + start_column: 63, + end_line: 13, + end_column: 65, + }, + }, + ], + }, + id: 32, + span: { + start_line: 13, + start_column: 49, + end_line: 13, + end_column: 66, + }, + }, + ], + }, + id: 30, + span: { + start_line: 13, + start_column: 34, + end_line: 13, + end_column: 67, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "called", + }, + id: 36, + span: { + start_line: 13, + start_column: 70, + end_line: 13, + end_column: 75, + }, + }, + { + expr: { + Atom: "uint", + }, + id: 37, + span: { + start_line: 13, + start_column: 77, + end_line: 13, + end_column: 80, + }, + }, + ], + }, + id: 35, + span: { + start_line: 13, + start_column: 69, + end_line: 13, + end_column: 81, + }, + }, + ], + }, + id: 28, + span: { + start_line: 13, + start_column: 18, + end_line: 13, + end_column: 82, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "ok", + }, + id: 39, + span: { + start_line: 14, + start_column: 6, + end_line: 14, + end_column: 7, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "map-set", + }, + id: 41, + span: { + start_line: 14, + start_column: 10, + end_line: 14, + end_column: 16, + }, + }, + { + expr: { + Atom: "context", + }, + id: 42, + span: { + start_line: 14, + start_column: 18, + end_line: 14, + end_column: 24, + }, + }, + { + expr: { + Atom: "function-name", + }, + id: 43, + span: { + start_line: 14, + start_column: 26, + end_line: 14, + end_column: 38, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "tuple", + }, + id: 45, + span: { + start_line: 0, + start_column: 0, + end_line: 0, + end_column: 0, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "called", + }, + id: 47, + span: { + start_line: 14, + start_column: 41, + end_line: 14, + end_column: 46, + }, + }, + { + expr: { + Atom: "called", + }, + id: 48, + span: { + start_line: 14, + start_column: 49, + end_line: 14, + end_column: 54, + }, + }, + ], + }, + id: 46, + span: { + start_line: 14, + start_column: 41, + end_line: 14, + end_column: 54, + }, + }, + ], + }, + id: 44, + span: { + start_line: 14, + start_column: 40, + end_line: 14, + end_column: 55, + }, + }, + ], + }, + id: 40, + span: { + start_line: 14, + start_column: 9, + end_line: 14, + end_column: 56, + }, + }, + ], + }, + id: 38, + span: { + start_line: 14, + start_column: 5, + end_line: 14, + end_column: 57, + }, + }, + ], + }, + id: 26, + span: { + start_line: 13, + start_column: 3, + end_line: 14, + end_column: 58, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "define-public", + }, + id: 50, + span: { + start_line: 16, + start_column: 2, + end_line: 16, + end_column: 14, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "test-no-trait", + }, + id: 52, + span: { + start_line: 16, + start_column: 17, + end_line: 16, + end_column: 29, + }, + }, + ], + }, + id: 51, + span: { + start_line: 16, + start_column: 16, + end_line: 16, + end_column: 30, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "ok", + }, + id: 54, + span: { + start_line: 17, + start_column: 4, + end_line: 17, + end_column: 5, + }, + }, + { + expr: { + Atom: "true", + }, + id: 55, + span: { + start_line: 17, + start_column: 7, + end_line: 17, + end_column: 10, + }, + }, + ], + }, + id: 53, + span: { + start_line: 17, + start_column: 3, + end_line: 17, + end_column: 11, + }, + }, + ], + }, + id: 49, + span: { + start_line: 16, + start_column: 1, + end_line: 18, + end_column: 1, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "define-public", + }, + id: 57, + span: { + start_line: 20, + start_column: 2, + end_line: 20, + end_column: 14, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "test-trait", + }, + id: 59, + span: { + start_line: 20, + start_column: 17, + end_line: 20, + end_column: 26, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "token", + }, + id: 61, + span: { + start_line: 20, + start_column: 29, + end_line: 20, + end_column: 33, + }, + }, + { + expr: { + TraitReference: [ + "ft-trait", + { + Imported: { + name: "sip-010-trait", + contract_identifier: { + issuer: [ + 22, + [ + 9, 159, 184, 137, 38, 216, 47, 48, + 178, 244, 14, 175, 62, 228, 35, 203, + 114, 91, 219, 59, + ], + ], + name: "sip-010-trait-ft-standard", + }, + }, + }, + ], + }, + id: 62, + span: { + start_line: 20, + start_column: 35, + end_line: 20, + end_column: 44, + }, + }, + ], + }, + id: 60, + span: { + start_line: 20, + start_column: 28, + end_line: 20, + end_column: 45, + }, + }, + ], + }, + id: 58, + span: { + start_line: 20, + start_column: 16, + end_line: 20, + end_column: 46, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "ok", + }, + id: 64, + span: { + start_line: 21, + start_column: 4, + end_line: 21, + end_column: 5, + }, + }, + { + expr: { + Atom: "true", + }, + id: 65, + span: { + start_line: 21, + start_column: 7, + end_line: 21, + end_column: 10, + }, + }, + ], + }, + id: 63, + span: { + start_line: 21, + start_column: 3, + end_line: 21, + end_column: 11, + }, + }, + ], + }, + id: 56, + span: { + start_line: 20, + start_column: 1, + end_line: 22, + end_column: 1, + }, + }, + ], + top_level_expression_sorting: [0, 1, 2, 3, 4, 5], + referenced_traits: {}, + implemented_traits: [], + }, + }, + directTrait2ndParameter: { + functionsInterfaces: [ + { + name: "function", + access: "public", + args: [], + outputs: { + type: { + response: { + ok: "bool", + error: "none", + }, + }, + }, + }, + { + name: "test-no-trait", + access: "public", + args: [], + outputs: { + type: { + response: { + ok: "bool", + error: "none", + }, + }, + }, + }, + { + name: "test-trait", + access: "public", + args: [ + { + name: "a", + type: "uint128", + }, + { + name: "token", + type: "trait_reference", + }, + ], + outputs: { + type: { + response: { + ok: "bool", + error: "none", + }, + }, + }, + }, + ], + ast: { + contract_identifier: { + issuer: [ + 26, + [ + 109, 120, 222, 123, 6, 37, 223, 191, 193, 108, 58, 138, 87, 53, 246, + 220, 61, 195, 242, 206, + ], + ], + name: "trait", + }, + pre_expressions: [], + expressions: [ + { + expr: { + List: [ + { + expr: { + Atom: "define-public", + }, + id: 2, + span: { + start_line: 1, + start_column: 2, + end_line: 1, + end_column: 14, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "function", + }, + id: 4, + span: { + start_line: 1, + start_column: 17, + end_line: 1, + end_column: 24, + }, + }, + ], + }, + id: 3, + span: { + start_line: 1, + start_column: 16, + end_line: 1, + end_column: 25, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "ok", + }, + id: 6, + span: { + start_line: 2, + start_column: 4, + end_line: 2, + end_column: 5, + }, + }, + { + expr: { + Atom: "true", + }, + id: 7, + span: { + start_line: 2, + start_column: 7, + end_line: 2, + end_column: 10, + }, + }, + ], + }, + id: 5, + span: { + start_line: 2, + start_column: 3, + end_line: 2, + end_column: 11, + }, + }, + ], + }, + id: 1, + span: { + start_line: 1, + start_column: 1, + end_line: 3, + end_column: 1, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "define-map", + }, + id: 9, + span: { + start_line: 6, + start_column: 2, + end_line: 6, + end_column: 11, + }, + }, + { + expr: { + Atom: "context", + }, + id: 10, + span: { + start_line: 6, + start_column: 13, + end_line: 6, + end_column: 19, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "string-ascii", + }, + id: 12, + span: { + start_line: 6, + start_column: 22, + end_line: 6, + end_column: 33, + }, + }, + { + expr: { + LiteralValue: { + Int: "100", + }, + }, + id: 13, + span: { + start_line: 6, + start_column: 35, + end_line: 6, + end_column: 37, + }, + }, + ], + }, + id: 11, + span: { + start_line: 6, + start_column: 21, + end_line: 6, + end_column: 38, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "tuple", + }, + id: 15, + span: { + start_line: 0, + start_column: 0, + end_line: 0, + end_column: 0, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "called", + }, + id: 17, + span: { + start_line: 7, + start_column: 5, + end_line: 7, + end_column: 10, + }, + }, + { + expr: { + Atom: "uint", + }, + id: 18, + span: { + start_line: 7, + start_column: 13, + end_line: 7, + end_column: 16, + }, + post_comments: [ + [ + "other data", + { + start_line: 8, + start_column: 5, + end_line: 8, + end_column: 17, + }, + ], + ], + }, + ], + }, + id: 16, + span: { + start_line: 7, + start_column: 5, + end_line: 7, + end_column: 16, + }, + }, + ], + }, + id: 14, + span: { + start_line: 6, + start_column: 40, + end_line: 9, + end_column: 3, + }, + }, + ], + }, + id: 8, + span: { + start_line: 6, + start_column: 1, + end_line: 9, + end_column: 4, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "define-public", + }, + id: 20, + span: { + start_line: 11, + start_column: 4, + end_line: 11, + end_column: 16, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "update-context", + }, + id: 22, + span: { + start_line: 11, + start_column: 19, + end_line: 11, + end_column: 32, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "function-name", + }, + id: 24, + span: { + start_line: 11, + start_column: 35, + end_line: 11, + end_column: 47, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "string-ascii", + }, + id: 26, + span: { + start_line: 11, + start_column: 50, + end_line: 11, + end_column: 61, + }, + }, + { + expr: { + LiteralValue: { + Int: "100", + }, + }, + id: 27, + span: { + start_line: 11, + start_column: 63, + end_line: 11, + end_column: 65, + }, + }, + ], + }, + id: 25, + span: { + start_line: 11, + start_column: 49, + end_line: 11, + end_column: 66, + }, + }, + ], + }, + id: 23, + span: { + start_line: 11, + start_column: 34, + end_line: 11, + end_column: 67, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "called", + }, + id: 29, + span: { + start_line: 11, + start_column: 70, + end_line: 11, + end_column: 75, + }, + }, + { + expr: { + Atom: "uint", + }, + id: 30, + span: { + start_line: 11, + start_column: 77, + end_line: 11, + end_column: 80, + }, + }, + ], + }, + id: 28, + span: { + start_line: 11, + start_column: 69, + end_line: 11, + end_column: 81, + }, + }, + ], + }, + id: 21, + span: { + start_line: 11, + start_column: 18, + end_line: 11, + end_column: 82, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "ok", + }, + id: 32, + span: { + start_line: 12, + start_column: 6, + end_line: 12, + end_column: 7, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "map-set", + }, + id: 34, + span: { + start_line: 12, + start_column: 10, + end_line: 12, + end_column: 16, + }, + }, + { + expr: { + Atom: "context", + }, + id: 35, + span: { + start_line: 12, + start_column: 18, + end_line: 12, + end_column: 24, + }, + }, + { + expr: { + Atom: "function-name", + }, + id: 36, + span: { + start_line: 12, + start_column: 26, + end_line: 12, + end_column: 38, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "tuple", + }, + id: 38, + span: { + start_line: 0, + start_column: 0, + end_line: 0, + end_column: 0, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "called", + }, + id: 40, + span: { + start_line: 12, + start_column: 41, + end_line: 12, + end_column: 46, + }, + }, + { + expr: { + Atom: "called", + }, + id: 41, + span: { + start_line: 12, + start_column: 49, + end_line: 12, + end_column: 54, + }, + }, + ], + }, + id: 39, + span: { + start_line: 12, + start_column: 41, + end_line: 12, + end_column: 54, + }, + }, + ], + }, + id: 37, + span: { + start_line: 12, + start_column: 40, + end_line: 12, + end_column: 55, + }, + }, + ], + }, + id: 33, + span: { + start_line: 12, + start_column: 9, + end_line: 12, + end_column: 56, + }, + }, + ], + }, + id: 31, + span: { + start_line: 12, + start_column: 5, + end_line: 12, + end_column: 57, + }, + }, + ], + }, + id: 19, + span: { + start_line: 11, + start_column: 3, + end_line: 12, + end_column: 58, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "use-trait", + }, + id: 43, + span: { + start_line: 14, + start_column: 2, + end_line: 14, + end_column: 10, + }, + }, + { + expr: { + Atom: "ft-trait", + }, + id: 44, + span: { + start_line: 14, + start_column: 12, + end_line: 14, + end_column: 19, + }, + }, + { + expr: { + Field: { + name: "sip-010-trait", + contract_identifier: { + issuer: [ + 22, + [ + 9, 159, 184, 137, 38, 216, 47, 48, 178, 244, 14, 175, + 62, 228, 35, 203, 114, 91, 219, 59, + ], + ], + name: "sip-010-trait-ft-standard", + }, + }, + }, + id: 45, + span: { + start_line: 14, + start_column: 21, + end_line: 14, + end_column: 101, + }, + }, + ], + }, + id: 42, + span: { + start_line: 14, + start_column: 1, + end_line: 14, + end_column: 102, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "define-public", + }, + id: 47, + span: { + start_line: 16, + start_column: 2, + end_line: 16, + end_column: 14, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "test-no-trait", + }, + id: 49, + span: { + start_line: 16, + start_column: 17, + end_line: 16, + end_column: 29, + }, + }, + ], + }, + id: 48, + span: { + start_line: 16, + start_column: 16, + end_line: 16, + end_column: 30, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "ok", + }, + id: 51, + span: { + start_line: 17, + start_column: 4, + end_line: 17, + end_column: 5, + }, + }, + { + expr: { + Atom: "true", + }, + id: 52, + span: { + start_line: 17, + start_column: 7, + end_line: 17, + end_column: 10, + }, + }, + ], + }, + id: 50, + span: { + start_line: 17, + start_column: 3, + end_line: 17, + end_column: 11, + }, + }, + ], + }, + id: 46, + span: { + start_line: 16, + start_column: 1, + end_line: 18, + end_column: 1, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "define-public", + }, + id: 54, + span: { + start_line: 20, + start_column: 2, + end_line: 20, + end_column: 14, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "test-trait", + }, + id: 56, + span: { + start_line: 20, + start_column: 17, + end_line: 20, + end_column: 26, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "a", + }, + id: 58, + span: { + start_line: 20, + start_column: 29, + end_line: 20, + end_column: 29, + }, + }, + { + expr: { + Atom: "uint", + }, + id: 59, + span: { + start_line: 20, + start_column: 31, + end_line: 20, + end_column: 34, + }, + }, + ], + }, + id: 57, + span: { + start_line: 20, + start_column: 28, + end_line: 20, + end_column: 35, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "token", + }, + id: 61, + span: { + start_line: 20, + start_column: 38, + end_line: 20, + end_column: 42, + }, + }, + { + expr: { + TraitReference: [ + "ft-trait", + { + Imported: { + name: "sip-010-trait", + contract_identifier: { + issuer: [ + 22, + [ + 9, 159, 184, 137, 38, 216, 47, 48, + 178, 244, 14, 175, 62, 228, 35, 203, + 114, 91, 219, 59, + ], + ], + name: "sip-010-trait-ft-standard", + }, + }, + }, + ], + }, + id: 62, + span: { + start_line: 20, + start_column: 44, + end_line: 20, + end_column: 53, + }, + }, + ], + }, + id: 60, + span: { + start_line: 20, + start_column: 37, + end_line: 20, + end_column: 54, + }, + }, + ], + }, + id: 55, + span: { + start_line: 20, + start_column: 16, + end_line: 20, + end_column: 55, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "ok", + }, + id: 64, + span: { + start_line: 21, + start_column: 4, + end_line: 21, + end_column: 5, + }, + }, + { + expr: { + Atom: "true", + }, + id: 65, + span: { + start_line: 21, + start_column: 7, + end_line: 21, + end_column: 10, + }, + }, + ], + }, + id: 63, + span: { + start_line: 21, + start_column: 3, + end_line: 21, + end_column: 11, + }, + }, + ], + }, + id: 53, + span: { + start_line: 20, + start_column: 1, + end_line: 22, + end_column: 1, + }, + }, + ], + top_level_expression_sorting: [0, 1, 2, 3, 4, 5], + referenced_traits: {}, + implemented_traits: [], + }, + }, + directTrait5thParameter: { + functionsInterfaces: [ + { + name: "function", + access: "public", + args: [], + outputs: { + type: { + response: { + ok: "bool", + error: "none", + }, + }, + }, + }, + { + name: "test-no-trait", + access: "public", + args: [], + outputs: { + type: { + response: { + ok: "bool", + error: "none", + }, + }, + }, + }, + { + name: "test-trait", + access: "public", + args: [ + { + name: "a", + type: "uint128", + }, + { + name: "b", + type: "int128", + }, + { + name: "c", + type: "bool", + }, + { + name: "d", + type: { + "string-ascii": { + length: 10, + }, + }, + }, + { + name: "e", + type: "trait_reference", + }, + ], + outputs: { + type: { + response: { + ok: "bool", + error: "none", + }, + }, + }, + }, + { + name: "update-context", + access: "public", + args: [ + { + name: "function-name", + type: { + "string-ascii": { + length: 100, + }, + }, + }, + { + name: "called", + type: "uint128", + }, + ], + outputs: { + type: { + response: { + ok: "bool", + error: "none", + }, + }, + }, + }, + ], + ast: { + contract_identifier: { + issuer: [ + 26, + [ + 109, 120, 222, 123, 6, 37, 223, 191, 193, 108, 58, 138, 87, 53, 246, + 220, 61, 195, 242, 206, + ], + ], + name: "trait", + }, + pre_expressions: [], + expressions: [ + { + expr: { + List: [ + { + expr: { + Atom: "define-public", + }, + id: 2, + span: { + start_line: 1, + start_column: 2, + end_line: 1, + end_column: 14, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "function", + }, + id: 4, + span: { + start_line: 1, + start_column: 17, + end_line: 1, + end_column: 24, + }, + }, + ], + }, + id: 3, + span: { + start_line: 1, + start_column: 16, + end_line: 1, + end_column: 25, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "ok", + }, + id: 6, + span: { + start_line: 2, + start_column: 4, + end_line: 2, + end_column: 5, + }, + }, + { + expr: { + Atom: "true", + }, + id: 7, + span: { + start_line: 2, + start_column: 7, + end_line: 2, + end_column: 10, + }, + }, + ], + }, + id: 5, + span: { + start_line: 2, + start_column: 3, + end_line: 2, + end_column: 11, + }, + }, + ], + }, + id: 1, + span: { + start_line: 1, + start_column: 1, + end_line: 3, + end_column: 1, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "define-map", + }, + id: 9, + span: { + start_line: 6, + start_column: 2, + end_line: 6, + end_column: 11, + }, + }, + { + expr: { + Atom: "context", + }, + id: 10, + span: { + start_line: 6, + start_column: 13, + end_line: 6, + end_column: 19, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "string-ascii", + }, + id: 12, + span: { + start_line: 6, + start_column: 22, + end_line: 6, + end_column: 33, + }, + }, + { + expr: { + LiteralValue: { + Int: "100", + }, + }, + id: 13, + span: { + start_line: 6, + start_column: 35, + end_line: 6, + end_column: 37, + }, + }, + ], + }, + id: 11, + span: { + start_line: 6, + start_column: 21, + end_line: 6, + end_column: 38, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "tuple", + }, + id: 15, + span: { + start_line: 0, + start_column: 0, + end_line: 0, + end_column: 0, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "called", + }, + id: 17, + span: { + start_line: 7, + start_column: 5, + end_line: 7, + end_column: 10, + }, + }, + { + expr: { + Atom: "uint", + }, + id: 18, + span: { + start_line: 7, + start_column: 13, + end_line: 7, + end_column: 16, + }, + post_comments: [ + [ + "other data", + { + start_line: 8, + start_column: 5, + end_line: 8, + end_column: 17, + }, + ], + ], + }, + ], + }, + id: 16, + span: { + start_line: 7, + start_column: 5, + end_line: 7, + end_column: 16, + }, + }, + ], + }, + id: 14, + span: { + start_line: 6, + start_column: 40, + end_line: 9, + end_column: 3, + }, + }, + ], + }, + id: 8, + span: { + start_line: 6, + start_column: 1, + end_line: 9, + end_column: 4, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "define-public", + }, + id: 20, + span: { + start_line: 11, + start_column: 4, + end_line: 11, + end_column: 16, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "update-context", + }, + id: 22, + span: { + start_line: 11, + start_column: 19, + end_line: 11, + end_column: 32, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "function-name", + }, + id: 24, + span: { + start_line: 11, + start_column: 35, + end_line: 11, + end_column: 47, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "string-ascii", + }, + id: 26, + span: { + start_line: 11, + start_column: 50, + end_line: 11, + end_column: 61, + }, + }, + { + expr: { + LiteralValue: { + Int: "100", + }, + }, + id: 27, + span: { + start_line: 11, + start_column: 63, + end_line: 11, + end_column: 65, + }, + }, + ], + }, + id: 25, + span: { + start_line: 11, + start_column: 49, + end_line: 11, + end_column: 66, + }, + }, + ], + }, + id: 23, + span: { + start_line: 11, + start_column: 34, + end_line: 11, + end_column: 67, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "called", + }, + id: 29, + span: { + start_line: 11, + start_column: 70, + end_line: 11, + end_column: 75, + }, + }, + { + expr: { + Atom: "uint", + }, + id: 30, + span: { + start_line: 11, + start_column: 77, + end_line: 11, + end_column: 80, + }, + }, + ], + }, + id: 28, + span: { + start_line: 11, + start_column: 69, + end_line: 11, + end_column: 81, + }, + }, + ], + }, + id: 21, + span: { + start_line: 11, + start_column: 18, + end_line: 11, + end_column: 82, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "ok", + }, + id: 32, + span: { + start_line: 12, + start_column: 6, + end_line: 12, + end_column: 7, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "map-set", + }, + id: 34, + span: { + start_line: 12, + start_column: 10, + end_line: 12, + end_column: 16, + }, + }, + { + expr: { + Atom: "context", + }, + id: 35, + span: { + start_line: 12, + start_column: 18, + end_line: 12, + end_column: 24, + }, + }, + { + expr: { + Atom: "function-name", + }, + id: 36, + span: { + start_line: 12, + start_column: 26, + end_line: 12, + end_column: 38, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "tuple", + }, + id: 38, + span: { + start_line: 0, + start_column: 0, + end_line: 0, + end_column: 0, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "called", + }, + id: 40, + span: { + start_line: 12, + start_column: 41, + end_line: 12, + end_column: 46, + }, + }, + { + expr: { + Atom: "called", + }, + id: 41, + span: { + start_line: 12, + start_column: 49, + end_line: 12, + end_column: 54, + }, + }, + ], + }, + id: 39, + span: { + start_line: 12, + start_column: 41, + end_line: 12, + end_column: 54, + }, + }, + ], + }, + id: 37, + span: { + start_line: 12, + start_column: 40, + end_line: 12, + end_column: 55, + }, + }, + ], + }, + id: 33, + span: { + start_line: 12, + start_column: 9, + end_line: 12, + end_column: 56, + }, + }, + ], + }, + id: 31, + span: { + start_line: 12, + start_column: 5, + end_line: 12, + end_column: 57, + }, + }, + ], + }, + id: 19, + span: { + start_line: 11, + start_column: 3, + end_line: 12, + end_column: 58, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "use-trait", + }, + id: 43, + span: { + start_line: 14, + start_column: 2, + end_line: 14, + end_column: 10, + }, + }, + { + expr: { + Atom: "ft-trait", + }, + id: 44, + span: { + start_line: 14, + start_column: 12, + end_line: 14, + end_column: 19, + }, + }, + { + expr: { + Field: { + name: "sip-010-trait", + contract_identifier: { + issuer: [ + 22, + [ + 9, 159, 184, 137, 38, 216, 47, 48, 178, 244, 14, 175, + 62, 228, 35, 203, 114, 91, 219, 59, + ], + ], + name: "sip-010-trait-ft-standard", + }, + }, + }, + id: 45, + span: { + start_line: 14, + start_column: 21, + end_line: 14, + end_column: 101, + }, + }, + ], + }, + id: 42, + span: { + start_line: 14, + start_column: 1, + end_line: 14, + end_column: 102, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "define-public", + }, + id: 47, + span: { + start_line: 16, + start_column: 2, + end_line: 16, + end_column: 14, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "test-no-trait", + }, + id: 49, + span: { + start_line: 16, + start_column: 17, + end_line: 16, + end_column: 29, + }, + }, + ], + }, + id: 48, + span: { + start_line: 16, + start_column: 16, + end_line: 16, + end_column: 30, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "ok", + }, + id: 51, + span: { + start_line: 17, + start_column: 4, + end_line: 17, + end_column: 5, + }, + }, + { + expr: { + Atom: "true", + }, + id: 52, + span: { + start_line: 17, + start_column: 7, + end_line: 17, + end_column: 10, + }, + }, + ], + }, + id: 50, + span: { + start_line: 17, + start_column: 3, + end_line: 17, + end_column: 11, + }, + }, + ], + }, + id: 46, + span: { + start_line: 16, + start_column: 1, + end_line: 18, + end_column: 1, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "define-public", + }, + id: 54, + span: { + start_line: 20, + start_column: 2, + end_line: 20, + end_column: 14, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "test-trait", + }, + id: 56, + span: { + start_line: 20, + start_column: 17, + end_line: 20, + end_column: 26, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "a", + }, + id: 58, + span: { + start_line: 20, + start_column: 29, + end_line: 20, + end_column: 29, + }, + }, + { + expr: { + Atom: "uint", + }, + id: 59, + span: { + start_line: 20, + start_column: 31, + end_line: 20, + end_column: 34, + }, + }, + ], + }, + id: 57, + span: { + start_line: 20, + start_column: 28, + end_line: 20, + end_column: 35, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "b", + }, + id: 61, + span: { + start_line: 20, + start_column: 38, + end_line: 20, + end_column: 38, + }, + }, + { + expr: { + Atom: "int", + }, + id: 62, + span: { + start_line: 20, + start_column: 40, + end_line: 20, + end_column: 42, + }, + }, + ], + }, + id: 60, + span: { + start_line: 20, + start_column: 37, + end_line: 20, + end_column: 43, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "c", + }, + id: 64, + span: { + start_line: 20, + start_column: 46, + end_line: 20, + end_column: 46, + }, + }, + { + expr: { + Atom: "bool", + }, + id: 65, + span: { + start_line: 20, + start_column: 48, + end_line: 20, + end_column: 51, + }, + }, + ], + }, + id: 63, + span: { + start_line: 20, + start_column: 45, + end_line: 20, + end_column: 52, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "d", + }, + id: 67, + span: { + start_line: 20, + start_column: 55, + end_line: 20, + end_column: 55, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "string-ascii", + }, + id: 69, + span: { + start_line: 20, + start_column: 58, + end_line: 20, + end_column: 69, + }, + }, + { + expr: { + LiteralValue: { + Int: "10", + }, + }, + id: 70, + span: { + start_line: 20, + start_column: 71, + end_line: 20, + end_column: 72, + }, + }, + ], + }, + id: 68, + span: { + start_line: 20, + start_column: 57, + end_line: 20, + end_column: 73, + }, + }, + ], + }, + id: 66, + span: { + start_line: 20, + start_column: 54, + end_line: 20, + end_column: 74, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "e", + }, + id: 72, + span: { + start_line: 20, + start_column: 77, + end_line: 20, + end_column: 77, + }, + }, + { + expr: { + TraitReference: [ + "ft-trait", + { + Imported: { + name: "sip-010-trait", + contract_identifier: { + issuer: [ + 22, + [ + 9, 159, 184, 137, 38, 216, 47, 48, + 178, 244, 14, 175, 62, 228, 35, 203, + 114, 91, 219, 59, + ], + ], + name: "sip-010-trait-ft-standard", + }, + }, + }, + ], + }, + id: 73, + span: { + start_line: 20, + start_column: 79, + end_line: 20, + end_column: 88, + }, + }, + ], + }, + id: 71, + span: { + start_line: 20, + start_column: 76, + end_line: 20, + end_column: 89, + }, + }, + ], + }, + id: 55, + span: { + start_line: 20, + start_column: 16, + end_line: 20, + end_column: 90, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "ok", + }, + id: 75, + span: { + start_line: 21, + start_column: 4, + end_line: 21, + end_column: 5, + }, + }, + { + expr: { + Atom: "true", + }, + id: 76, + span: { + start_line: 21, + start_column: 7, + end_line: 21, + end_column: 10, + }, + }, + ], + }, + id: 74, + span: { + start_line: 21, + start_column: 3, + end_line: 21, + end_column: 11, + }, + }, + ], + }, + id: 53, + span: { + start_line: 20, + start_column: 1, + end_line: 22, + end_column: 1, }, }, ], - outputs: { - type: { - response: { - ok: "bool", - error: "uint128", - }, - }, - }, - } as ContractInterfaceFunction; - - // Act - const result = isTraitReferenceFunction(responseWithTraitFunction); - - // Assert - expect(result).toBe(true); - }); - - it("returns false for unexpected argument types", async () => { - // Arrange - const unexpectedTypeFunction = { - name: "unexpected-type-function", - access: "public", - args: [{ name: "unexpectedArg", type: "custom_type" as any }], - outputs: { - type: { - response: { - ok: "bool", - error: "uint128", - }, - }, - }, - } as ContractInterfaceFunction; - - // Act - const result = isTraitReferenceFunction(unexpectedTypeFunction); - - // Assert - expect(result).toBe(false); - }); - - it("returns false for an argument with an unrecognized complex type", async () => { - // Arrange - const unrecognizedTypeFunction = { - name: "unrecognized-type-function", - access: "public", - args: [{ name: "unknownArg", type: { unknown: "some_value" } as any }], - outputs: { type: "bool" }, - } as ContractInterfaceFunction; - - // Act - const result = isTraitReferenceFunction(unrecognizedTypeFunction); - - // Assert - expect(result).toBe(false); - }); -}); - -const testInputs = { - directTrait1stParameter: { + top_level_expression_sorting: [0, 1, 2, 3, 4, 5], + referenced_traits: {}, + implemented_traits: [], + }, + }, + listTraitParameter: { functionsInterfaces: [ { name: "function", @@ -1002,8 +4363,13 @@ const testInputs = { access: "public", args: [ { - name: "token", - type: "trait_reference", + name: "token-list", + type: { + list: { + type: "trait_reference", + length: 5, + }, + }, }, ], outputs: { @@ -1060,74 +4426,13 @@ const testInputs = { List: [ { expr: { - Atom: "use-trait", + Atom: "define-public", }, id: 2, span: { start_line: 1, start_column: 2, end_line: 1, - end_column: 10, - }, - }, - { - expr: { - Atom: "ft-trait", - }, - id: 3, - span: { - start_line: 1, - start_column: 12, - end_line: 1, - end_column: 19, - }, - }, - { - expr: { - Field: { - name: "sip-010-trait", - contract_identifier: { - issuer: [ - 22, - [ - 9, 159, 184, 137, 38, 216, 47, 48, 178, 244, 14, 175, - 62, 228, 35, 203, 114, 91, 219, 59, - ], - ], - name: "sip-010-trait-ft-standard", - }, - }, - }, - id: 4, - span: { - start_line: 1, - start_column: 21, - end_line: 1, - end_column: 101, - }, - }, - ], - }, - id: 1, - span: { - start_line: 1, - start_column: 1, - end_line: 1, - end_column: 102, - }, - }, - { - expr: { - List: [ - { - expr: { - Atom: "define-public", - }, - id: 6, - span: { - start_line: 3, - start_column: 2, - end_line: 3, end_column: 14, }, }, @@ -1135,80 +4440,25 @@ const testInputs = { expr: { List: [ { - expr: { - Atom: "trait-transfer-function", - }, - id: 8, - span: { - start_line: 3, - start_column: 17, - end_line: 3, - end_column: 39, - }, - }, - { - expr: { - List: [ - { - expr: { - Atom: "token", - }, - id: 10, - span: { - start_line: 3, - start_column: 42, - end_line: 3, - end_column: 46, - }, - }, - { - expr: { - TraitReference: [ - "ft-trait", - { - Imported: { - name: "sip-010-trait", - contract_identifier: { - issuer: [ - 22, - [ - 9, 159, 184, 137, 38, 216, 47, 48, - 178, 244, 14, 175, 62, 228, 35, 203, - 114, 91, 219, 59, - ], - ], - name: "sip-010-trait-ft-standard", - }, - }, - }, - ], - }, - id: 11, - span: { - start_line: 3, - start_column: 48, - end_line: 3, - end_column: 57, - }, - }, - ], + expr: { + Atom: "function", }, - id: 9, + id: 4, span: { - start_line: 3, - start_column: 41, - end_line: 3, - end_column: 58, + start_line: 1, + start_column: 17, + end_line: 1, + end_column: 24, }, }, ], }, - id: 7, + id: 3, span: { - start_line: 3, + start_line: 1, start_column: 16, - end_line: 3, - end_column: 59, + end_line: 1, + end_column: 25, }, }, { @@ -1218,11 +4468,11 @@ const testInputs = { expr: { Atom: "ok", }, - id: 13, + id: 6, span: { - start_line: 4, + start_line: 2, start_column: 4, - end_line: 4, + end_line: 2, end_column: 5, }, }, @@ -1230,31 +4480,31 @@ const testInputs = { expr: { Atom: "true", }, - id: 14, + id: 7, span: { - start_line: 4, + start_line: 2, start_column: 7, - end_line: 4, + end_line: 2, end_column: 10, }, }, ], }, - id: 12, + id: 5, span: { - start_line: 4, + start_line: 2, start_column: 3, - end_line: 4, + end_line: 2, end_column: 11, }, }, ], }, - id: 5, + id: 1, span: { - start_line: 3, + start_line: 1, start_column: 1, - end_line: 5, + end_line: 3, end_column: 1, }, }, @@ -1265,11 +4515,11 @@ const testInputs = { expr: { Atom: "define-map", }, - id: 16, + id: 9, span: { - start_line: 8, + start_line: 6, start_column: 2, - end_line: 8, + end_line: 6, end_column: 11, }, }, @@ -1277,11 +4527,11 @@ const testInputs = { expr: { Atom: "context", }, - id: 17, + id: 10, span: { - start_line: 8, + start_line: 6, start_column: 13, - end_line: 8, + end_line: 6, end_column: 19, }, }, @@ -1292,11 +4542,11 @@ const testInputs = { expr: { Atom: "string-ascii", }, - id: 19, + id: 12, span: { - start_line: 8, + start_line: 6, start_column: 22, - end_line: 8, + end_line: 6, end_column: 33, }, }, @@ -1306,21 +4556,21 @@ const testInputs = { Int: "100", }, }, - id: 20, + id: 13, span: { - start_line: 8, + start_line: 6, start_column: 35, - end_line: 8, + end_line: 6, end_column: 37, }, }, ], }, - id: 18, + id: 11, span: { - start_line: 8, + start_line: 6, start_column: 21, - end_line: 8, + end_line: 6, end_column: 38, }, }, @@ -1331,7 +4581,7 @@ const testInputs = { expr: { Atom: "tuple", }, - id: 22, + id: 15, span: { start_line: 0, start_column: 0, @@ -1346,11 +4596,11 @@ const testInputs = { expr: { Atom: "called", }, - id: 24, + id: 17, span: { - start_line: 9, + start_line: 7, start_column: 5, - end_line: 9, + end_line: 7, end_column: 10, }, }, @@ -1358,20 +4608,20 @@ const testInputs = { expr: { Atom: "uint", }, - id: 25, + id: 18, span: { - start_line: 9, + start_line: 7, start_column: 13, - end_line: 9, + end_line: 7, end_column: 16, }, post_comments: [ [ "other data", { - start_line: 10, + start_line: 8, start_column: 5, - end_line: 10, + end_line: 8, end_column: 17, }, ], @@ -1379,31 +4629,31 @@ const testInputs = { }, ], }, - id: 23, + id: 16, span: { - start_line: 9, + start_line: 7, start_column: 5, - end_line: 9, + end_line: 7, end_column: 16, }, }, ], }, - id: 21, + id: 14, span: { - start_line: 8, + start_line: 6, start_column: 40, - end_line: 11, + end_line: 9, end_column: 3, }, }, ], }, - id: 15, + id: 8, span: { - start_line: 8, + start_line: 6, start_column: 1, - end_line: 11, + end_line: 9, end_column: 4, }, }, @@ -1414,11 +4664,11 @@ const testInputs = { expr: { Atom: "define-public", }, - id: 27, + id: 20, span: { - start_line: 13, + start_line: 11, start_column: 4, - end_line: 13, + end_line: 11, end_column: 16, }, }, @@ -1429,11 +4679,11 @@ const testInputs = { expr: { Atom: "update-context", }, - id: 29, + id: 22, span: { - start_line: 13, + start_line: 11, start_column: 19, - end_line: 13, + end_line: 11, end_column: 32, }, }, @@ -1444,11 +4694,11 @@ const testInputs = { expr: { Atom: "function-name", }, - id: 31, + id: 24, span: { - start_line: 13, + start_line: 11, start_column: 35, - end_line: 13, + end_line: 11, end_column: 47, }, }, @@ -1459,11 +4709,11 @@ const testInputs = { expr: { Atom: "string-ascii", }, - id: 33, + id: 26, span: { - start_line: 13, + start_line: 11, start_column: 50, - end_line: 13, + end_line: 11, end_column: 61, }, }, @@ -1473,31 +4723,31 @@ const testInputs = { Int: "100", }, }, - id: 34, + id: 27, span: { - start_line: 13, + start_line: 11, start_column: 63, - end_line: 13, + end_line: 11, end_column: 65, }, }, ], }, - id: 32, + id: 25, span: { - start_line: 13, + start_line: 11, start_column: 49, - end_line: 13, + end_line: 11, end_column: 66, }, }, ], }, - id: 30, + id: 23, span: { - start_line: 13, + start_line: 11, start_column: 34, - end_line: 13, + end_line: 11, end_column: 67, }, }, @@ -1508,11 +4758,11 @@ const testInputs = { expr: { Atom: "called", }, - id: 36, + id: 29, span: { - start_line: 13, + start_line: 11, start_column: 70, - end_line: 13, + end_line: 11, end_column: 75, }, }, @@ -1520,31 +4770,31 @@ const testInputs = { expr: { Atom: "uint", }, - id: 37, + id: 30, span: { - start_line: 13, + start_line: 11, start_column: 77, - end_line: 13, + end_line: 11, end_column: 80, }, }, ], }, - id: 35, + id: 28, span: { - start_line: 13, + start_line: 11, start_column: 69, - end_line: 13, + end_line: 11, end_column: 81, }, }, ], }, - id: 28, + id: 21, span: { - start_line: 13, + start_line: 11, start_column: 18, - end_line: 13, + end_line: 11, end_column: 82, }, }, @@ -1555,11 +4805,11 @@ const testInputs = { expr: { Atom: "ok", }, - id: 39, + id: 32, span: { - start_line: 14, + start_line: 12, start_column: 6, - end_line: 14, + end_line: 12, end_column: 7, }, }, @@ -1570,11 +4820,11 @@ const testInputs = { expr: { Atom: "map-set", }, - id: 41, + id: 34, span: { - start_line: 14, + start_line: 12, start_column: 10, - end_line: 14, + end_line: 12, end_column: 16, }, }, @@ -1582,11 +4832,11 @@ const testInputs = { expr: { Atom: "context", }, - id: 42, + id: 35, span: { - start_line: 14, + start_line: 12, start_column: 18, - end_line: 14, + end_line: 12, end_column: 24, }, }, @@ -1594,11 +4844,11 @@ const testInputs = { expr: { Atom: "function-name", }, - id: 43, + id: 36, span: { - start_line: 14, + start_line: 12, start_column: 26, - end_line: 14, + end_line: 12, end_column: 38, }, }, @@ -1609,7 +4859,7 @@ const testInputs = { expr: { Atom: "tuple", }, - id: 45, + id: 38, span: { start_line: 0, start_column: 0, @@ -1624,11 +4874,11 @@ const testInputs = { expr: { Atom: "called", }, - id: 47, + id: 40, span: { - start_line: 14, + start_line: 12, start_column: 41, - end_line: 14, + end_line: 12, end_column: 46, }, }, @@ -1636,62 +4886,123 @@ const testInputs = { expr: { Atom: "called", }, - id: 48, + id: 41, span: { - start_line: 14, + start_line: 12, start_column: 49, - end_line: 14, + end_line: 12, end_column: 54, }, }, ], }, - id: 46, + id: 39, span: { - start_line: 14, + start_line: 12, start_column: 41, - end_line: 14, + end_line: 12, end_column: 54, }, }, ], }, - id: 44, + id: 37, span: { - start_line: 14, + start_line: 12, start_column: 40, - end_line: 14, + end_line: 12, end_column: 55, }, }, ], - }, - id: 40, - span: { - start_line: 14, - start_column: 9, - end_line: 14, - end_column: 56, - }, + }, + id: 33, + span: { + start_line: 12, + start_column: 9, + end_line: 12, + end_column: 56, + }, + }, + ], + }, + id: 31, + span: { + start_line: 12, + start_column: 5, + end_line: 12, + end_column: 57, + }, + }, + ], + }, + id: 19, + span: { + start_line: 11, + start_column: 3, + end_line: 12, + end_column: 58, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "use-trait", + }, + id: 43, + span: { + start_line: 14, + start_column: 2, + end_line: 14, + end_column: 10, + }, + }, + { + expr: { + Atom: "ft-trait", + }, + id: 44, + span: { + start_line: 14, + start_column: 12, + end_line: 14, + end_column: 19, + }, + }, + { + expr: { + Field: { + name: "sip-010-trait", + contract_identifier: { + issuer: [ + 22, + [ + 9, 159, 184, 137, 38, 216, 47, 48, 178, 244, 14, 175, + 62, 228, 35, 203, 114, 91, 219, 59, + ], + ], + name: "sip-010-trait-ft-standard", }, - ], + }, }, - id: 38, + id: 45, span: { start_line: 14, - start_column: 5, + start_column: 21, end_line: 14, - end_column: 57, + end_column: 101, }, }, ], }, - id: 26, + id: 42, span: { - start_line: 13, - start_column: 3, + start_line: 14, + start_column: 1, end_line: 14, - end_column: 58, + end_column: 102, }, }, { @@ -1701,7 +5012,7 @@ const testInputs = { expr: { Atom: "define-public", }, - id: 50, + id: 47, span: { start_line: 16, start_column: 2, @@ -1716,7 +5027,7 @@ const testInputs = { expr: { Atom: "test-no-trait", }, - id: 52, + id: 49, span: { start_line: 16, start_column: 17, @@ -1726,7 +5037,7 @@ const testInputs = { }, ], }, - id: 51, + id: 48, span: { start_line: 16, start_column: 16, @@ -1741,7 +5052,7 @@ const testInputs = { expr: { Atom: "ok", }, - id: 54, + id: 51, span: { start_line: 17, start_column: 4, @@ -1753,7 +5064,7 @@ const testInputs = { expr: { Atom: "true", }, - id: 55, + id: 52, span: { start_line: 17, start_column: 7, @@ -1763,7 +5074,7 @@ const testInputs = { }, ], }, - id: 53, + id: 50, span: { start_line: 17, start_column: 3, @@ -1773,7 +5084,7 @@ const testInputs = { }, ], }, - id: 49, + id: 46, span: { start_line: 16, start_column: 1, @@ -1788,7 +5099,7 @@ const testInputs = { expr: { Atom: "define-public", }, - id: 57, + id: 54, span: { start_line: 20, start_column: 2, @@ -1803,7 +5114,7 @@ const testInputs = { expr: { Atom: "test-trait", }, - id: 59, + id: 56, span: { start_line: 20, start_column: 17, @@ -1816,64 +5127,103 @@ const testInputs = { List: [ { expr: { - Atom: "token", + Atom: "token-list", }, - id: 61, + id: 58, span: { start_line: 20, start_column: 29, end_line: 20, - end_column: 33, + end_column: 38, }, }, { expr: { - TraitReference: [ - "ft-trait", + List: [ { - Imported: { - name: "sip-010-trait", - contract_identifier: { - issuer: [ - 22, - [ - 9, 159, 184, 137, 38, 216, 47, 48, - 178, 244, 14, 175, 62, 228, 35, 203, - 114, 91, 219, 59, - ], - ], - name: "sip-010-trait-ft-standard", + expr: { + Atom: "list", + }, + id: 60, + span: { + start_line: 20, + start_column: 41, + end_line: 20, + end_column: 44, + }, + }, + { + expr: { + LiteralValue: { + Int: "5", }, }, + id: 61, + span: { + start_line: 20, + start_column: 46, + end_line: 20, + end_column: 46, + }, + }, + { + expr: { + TraitReference: [ + "ft-trait", + { + Imported: { + name: "sip-010-trait", + contract_identifier: { + issuer: [ + 22, + [ + 9, 159, 184, 137, 38, 216, 47, + 48, 178, 244, 14, 175, 62, 228, + 35, 203, 114, 91, 219, 59, + ], + ], + name: "sip-010-trait-ft-standard", + }, + }, + }, + ], + }, + id: 62, + span: { + start_line: 20, + start_column: 48, + end_line: 20, + end_column: 57, + }, }, ], }, - id: 62, + id: 59, span: { start_line: 20, - start_column: 35, + start_column: 40, end_line: 20, - end_column: 44, + end_column: 58, }, }, ], }, - id: 60, + id: 57, span: { start_line: 20, start_column: 28, end_line: 20, - end_column: 45, + end_column: 59, }, }, ], }, - id: 58, + id: 55, span: { start_line: 20, start_column: 16, end_line: 20, - end_column: 46, + end_column: 60, }, }, { @@ -1915,7 +5265,7 @@ const testInputs = { }, ], }, - id: 56, + id: 53, span: { start_line: 20, start_column: 1, @@ -1929,7 +5279,7 @@ const testInputs = { implemented_traits: [], }, }, - directTrait2ndParameter: { + tupleTraitParameter: { functionsInterfaces: [ { name: "function", @@ -1962,12 +5312,41 @@ const testInputs = { access: "public", args: [ { - name: "a", - type: "uint128", + name: "tuple-param", + type: { + tuple: [ + { + name: "token", + type: "trait_reference", + }, + ], + }, + }, + ], + outputs: { + type: { + response: { + ok: "bool", + error: "none", + }, + }, + }, + }, + { + name: "update-context", + access: "public", + args: [ + { + name: "function-name", + type: { + "string-ascii": { + length: 100, + }, + }, }, { - name: "token", - type: "trait_reference", + name: "called", + type: "uint128", }, ], outputs: { @@ -2675,60 +6054,23 @@ const testInputs = { span: { start_line: 20, start_column: 2, - end_line: 20, - end_column: 14, - }, - }, - { - expr: { - List: [ - { - expr: { - Atom: "test-trait", - }, - id: 56, - span: { - start_line: 20, - start_column: 17, - end_line: 20, - end_column: 26, - }, - }, - { - expr: { - List: [ - { - expr: { - Atom: "a", - }, - id: 58, - span: { - start_line: 20, - start_column: 29, - end_line: 20, - end_column: 29, - }, - }, - { - expr: { - Atom: "uint", - }, - id: 59, - span: { - start_line: 20, - start_column: 31, - end_line: 20, - end_column: 34, - }, - }, - ], + end_line: 20, + end_column: 14, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "test-trait", }, - id: 57, + id: 56, span: { start_line: 20, - start_column: 28, + start_column: 17, end_line: 20, - end_column: 35, + end_column: 26, }, }, { @@ -2736,54 +6078,105 @@ const testInputs = { List: [ { expr: { - Atom: "token", + Atom: "tuple-param", }, - id: 61, + id: 58, span: { start_line: 20, - start_column: 38, + start_column: 29, end_line: 20, - end_column: 42, + end_column: 39, }, }, { expr: { - TraitReference: [ - "ft-trait", + List: [ { - Imported: { - name: "sip-010-trait", - contract_identifier: { - issuer: [ - 22, - [ - 9, 159, 184, 137, 38, 216, 47, 48, - 178, 244, 14, 175, 62, 228, 35, 203, - 114, 91, 219, 59, - ], - ], - name: "sip-010-trait-ft-standard", - }, + expr: { + Atom: "tuple", + }, + id: 60, + span: { + start_line: 0, + start_column: 0, + end_line: 0, + end_column: 0, + }, + }, + { + expr: { + List: [ + { + expr: { + Atom: "token", + }, + id: 62, + span: { + start_line: 20, + start_column: 42, + end_line: 20, + end_column: 46, + }, + }, + { + expr: { + TraitReference: [ + "ft-trait", + { + Imported: { + name: "sip-010-trait", + contract_identifier: { + issuer: [ + 22, + [ + 9, 159, 184, 137, 38, 216, + 47, 48, 178, 244, 14, 175, + 62, 228, 35, 203, 114, 91, + 219, 59, + ], + ], + name: "sip-010-trait-ft-standard", + }, + }, + }, + ], + }, + id: 63, + span: { + start_line: 20, + start_column: 49, + end_line: 20, + end_column: 58, + }, + }, + ], + }, + id: 61, + span: { + start_line: 20, + start_column: 42, + end_line: 20, + end_column: 58, }, }, ], }, - id: 62, + id: 59, span: { start_line: 20, - start_column: 44, + start_column: 41, end_line: 20, - end_column: 53, + end_column: 59, }, }, ], }, - id: 60, + id: 57, span: { start_line: 20, - start_column: 37, + start_column: 28, end_line: 20, - end_column: 54, + end_column: 60, }, }, ], @@ -2793,7 +6186,7 @@ const testInputs = { start_line: 20, start_column: 16, end_line: 20, - end_column: 55, + end_column: 61, }, }, { @@ -2803,7 +6196,7 @@ const testInputs = { expr: { Atom: "ok", }, - id: 64, + id: 65, span: { start_line: 21, start_column: 4, @@ -2815,7 +6208,7 @@ const testInputs = { expr: { Atom: "true", }, - id: 65, + id: 66, span: { start_line: 21, start_column: 7, @@ -2825,7 +6218,7 @@ const testInputs = { }, ], }, - id: 63, + id: 64, span: { start_line: 21, start_column: 3, @@ -2849,7 +6242,7 @@ const testInputs = { implemented_traits: [], }, }, - directTrait5thParameter: { + responseOkTraitParameter: { functionsInterfaces: [ { name: "function", @@ -2882,29 +6275,14 @@ const testInputs = { access: "public", args: [ { - name: "a", - type: "uint128", - }, - { - name: "b", - type: "int128", - }, - { - name: "c", - type: "bool", - }, - { - name: "d", + name: "resp-trait-param", type: { - "string-ascii": { - length: 10, + response: { + ok: "trait_reference", + error: "uint128", }, }, }, - { - name: "e", - type: "trait_reference", - }, ], outputs: { type: { @@ -3653,118 +7031,7 @@ const testInputs = { start_line: 20, start_column: 17, end_line: 20, - end_column: 26, - }, - }, - { - expr: { - List: [ - { - expr: { - Atom: "a", - }, - id: 58, - span: { - start_line: 20, - start_column: 29, - end_line: 20, - end_column: 29, - }, - }, - { - expr: { - Atom: "uint", - }, - id: 59, - span: { - start_line: 20, - start_column: 31, - end_line: 20, - end_column: 34, - }, - }, - ], - }, - id: 57, - span: { - start_line: 20, - start_column: 28, - end_line: 20, - end_column: 35, - }, - }, - { - expr: { - List: [ - { - expr: { - Atom: "b", - }, - id: 61, - span: { - start_line: 20, - start_column: 38, - end_line: 20, - end_column: 38, - }, - }, - { - expr: { - Atom: "int", - }, - id: 62, - span: { - start_line: 20, - start_column: 40, - end_line: 20, - end_column: 42, - }, - }, - ], - }, - id: 60, - span: { - start_line: 20, - start_column: 37, - end_line: 20, - end_column: 43, - }, - }, - { - expr: { - List: [ - { - expr: { - Atom: "c", - }, - id: 64, - span: { - start_line: 20, - start_column: 46, - end_line: 20, - end_column: 46, - }, - }, - { - expr: { - Atom: "bool", - }, - id: 65, - span: { - start_line: 20, - start_column: 48, - end_line: 20, - end_column: 51, - }, - }, - ], - }, - id: 63, - span: { - start_line: 20, - start_column: 45, - end_line: 20, - end_column: 52, + end_column: 26, }, }, { @@ -3772,14 +7039,14 @@ const testInputs = { List: [ { expr: { - Atom: "d", + Atom: "resp-trait-param", }, - id: 67, + id: 58, span: { start_line: 20, - start_column: 55, + start_column: 29, end_line: 20, - end_column: 55, + end_column: 44, }, }, { @@ -3787,103 +7054,76 @@ const testInputs = { List: [ { expr: { - Atom: "string-ascii", + Atom: "response", }, - id: 69, + id: 60, span: { start_line: 20, - start_column: 58, + start_column: 47, end_line: 20, - end_column: 69, + end_column: 54, }, }, { expr: { - LiteralValue: { - Int: "10", - }, + TraitReference: [ + "ft-trait", + { + Imported: { + name: "sip-010-trait", + contract_identifier: { + issuer: [ + 22, + [ + 9, 159, 184, 137, 38, 216, 47, + 48, 178, 244, 14, 175, 62, 228, + 35, 203, 114, 91, 219, 59, + ], + ], + name: "sip-010-trait-ft-standard", + }, + }, + }, + ], }, - id: 70, + id: 61, span: { start_line: 20, - start_column: 71, + start_column: 56, end_line: 20, - end_column: 72, + end_column: 65, }, }, - ], - }, - id: 68, - span: { - start_line: 20, - start_column: 57, - end_line: 20, - end_column: 73, - }, - }, - ], - }, - id: 66, - span: { - start_line: 20, - start_column: 54, - end_line: 20, - end_column: 74, - }, - }, - { - expr: { - List: [ - { - expr: { - Atom: "e", - }, - id: 72, - span: { - start_line: 20, - start_column: 77, - end_line: 20, - end_column: 77, - }, - }, - { - expr: { - TraitReference: [ - "ft-trait", { - Imported: { - name: "sip-010-trait", - contract_identifier: { - issuer: [ - 22, - [ - 9, 159, 184, 137, 38, 216, 47, 48, - 178, 244, 14, 175, 62, 228, 35, 203, - 114, 91, 219, 59, - ], - ], - name: "sip-010-trait-ft-standard", - }, + expr: { + Atom: "uint", + }, + id: 62, + span: { + start_line: 20, + start_column: 67, + end_line: 20, + end_column: 70, }, }, ], }, - id: 73, + id: 59, span: { start_line: 20, - start_column: 79, + start_column: 46, end_line: 20, - end_column: 88, + end_column: 71, }, }, ], }, - id: 71, + id: 57, span: { start_line: 20, - start_column: 76, + start_column: 28, end_line: 20, - end_column: 89, + end_column: 72, }, }, ], @@ -3893,7 +7133,7 @@ const testInputs = { start_line: 20, start_column: 16, end_line: 20, - end_column: 90, + end_column: 73, }, }, { @@ -3903,7 +7143,7 @@ const testInputs = { expr: { Atom: "ok", }, - id: 75, + id: 64, span: { start_line: 21, start_column: 4, @@ -3915,7 +7155,7 @@ const testInputs = { expr: { Atom: "true", }, - id: 76, + id: 65, span: { start_line: 21, start_column: 7, @@ -3925,7 +7165,7 @@ const testInputs = { }, ], }, - id: 74, + id: 63, span: { start_line: 21, start_column: 3, @@ -3949,7 +7189,7 @@ const testInputs = { implemented_traits: [], }, }, - listTraitParameter: { + responseErrTraitParameter: { functionsInterfaces: [ { name: "function", @@ -3982,11 +7222,11 @@ const testInputs = { access: "public", args: [ { - name: "token-list", + name: "resp-trait-param", type: { - list: { - type: "trait_reference", - length: 5, + response: { + ok: "uint128", + error: "trait_reference", }, }, }, @@ -4746,14 +7986,14 @@ const testInputs = { List: [ { expr: { - Atom: "token-list", + Atom: "resp-trait-param", }, id: 58, span: { start_line: 20, start_column: 29, end_line: 20, - end_column: 38, + end_column: 44, }, }, { @@ -4761,28 +8001,26 @@ const testInputs = { List: [ { expr: { - Atom: "list", + Atom: "response", }, id: 60, span: { start_line: 20, - start_column: 41, + start_column: 47, end_line: 20, - end_column: 44, + end_column: 54, }, }, { expr: { - LiteralValue: { - Int: "5", - }, + Atom: "uint", }, id: 61, span: { start_line: 20, - start_column: 46, + start_column: 56, end_line: 20, - end_column: 46, + end_column: 59, }, }, { @@ -4810,9 +8048,9 @@ const testInputs = { id: 62, span: { start_line: 20, - start_column: 48, + start_column: 61, end_line: 20, - end_column: 57, + end_column: 70, }, }, ], @@ -4820,9 +8058,9 @@ const testInputs = { id: 59, span: { start_line: 20, - start_column: 40, + start_column: 46, end_line: 20, - end_column: 58, + end_column: 71, }, }, ], @@ -4832,7 +8070,7 @@ const testInputs = { start_line: 20, start_column: 28, end_line: 20, - end_column: 59, + end_column: 72, }, }, ], @@ -4842,7 +8080,7 @@ const testInputs = { start_line: 20, start_column: 16, end_line: 20, - end_column: 60, + end_column: 73, }, }, { @@ -4898,7 +8136,7 @@ const testInputs = { implemented_traits: [], }, }, - tupleTraitParameter: { + responseBothTraitParameter: { functionsInterfaces: [ { name: "function", @@ -4931,14 +8169,12 @@ const testInputs = { access: "public", args: [ { - name: "tuple-param", + name: "resp-trait-param", type: { - tuple: [ - { - name: "token", - type: "trait_reference", - }, - ], + response: { + ok: "trait_reference", + error: "trait_reference", + }, }, }, ], @@ -5697,14 +8933,14 @@ const testInputs = { List: [ { expr: { - Atom: "tuple-param", + Atom: "resp-trait-param", }, id: 58, span: { start_line: 20, start_column: 29, end_line: 20, - end_column: 39, + end_column: 44, }, }, { @@ -5712,70 +8948,74 @@ const testInputs = { List: [ { expr: { - Atom: "tuple", + Atom: "response", }, id: 60, span: { - start_line: 0, - start_column: 0, - end_line: 0, - end_column: 0, + start_line: 20, + start_column: 47, + end_line: 20, + end_column: 54, }, }, { expr: { - List: [ + TraitReference: [ + "ft-trait", { - expr: { - Atom: "token", - }, - id: 62, - span: { - start_line: 20, - start_column: 42, - end_line: 20, - end_column: 46, + Imported: { + name: "sip-010-trait", + contract_identifier: { + issuer: [ + 22, + [ + 9, 159, 184, 137, 38, 216, 47, + 48, 178, 244, 14, 175, 62, 228, + 35, 203, 114, 91, 219, 59, + ], + ], + name: "sip-010-trait-ft-standard", + }, }, }, + ], + }, + id: 61, + span: { + start_line: 20, + start_column: 56, + end_line: 20, + end_column: 65, + }, + }, + { + expr: { + TraitReference: [ + "ft-trait", { - expr: { - TraitReference: [ - "ft-trait", - { - Imported: { - name: "sip-010-trait", - contract_identifier: { - issuer: [ - 22, - [ - 9, 159, 184, 137, 38, 216, - 47, 48, 178, 244, 14, 175, - 62, 228, 35, 203, 114, 91, - 219, 59, - ], - ], - name: "sip-010-trait-ft-standard", - }, - }, - }, - ], - }, - id: 63, - span: { - start_line: 20, - start_column: 49, - end_line: 20, - end_column: 58, + Imported: { + name: "sip-010-trait", + contract_identifier: { + issuer: [ + 22, + [ + 9, 159, 184, 137, 38, 216, 47, + 48, 178, 244, 14, 175, 62, 228, + 35, 203, 114, 91, 219, 59, + ], + ], + name: "sip-010-trait-ft-standard", + }, }, }, ], }, - id: 61, + id: 62, span: { start_line: 20, - start_column: 42, + start_column: 67, end_line: 20, - end_column: 58, + end_column: 76, }, }, ], @@ -5783,9 +9023,9 @@ const testInputs = { id: 59, span: { start_line: 20, - start_column: 41, + start_column: 46, end_line: 20, - end_column: 59, + end_column: 77, }, }, ], @@ -5795,7 +9035,7 @@ const testInputs = { start_line: 20, start_column: 28, end_line: 20, - end_column: 60, + end_column: 78, }, }, ], @@ -5805,7 +9045,7 @@ const testInputs = { start_line: 20, start_column: 16, end_line: 20, - end_column: 61, + end_column: 79, }, }, { @@ -5815,7 +9055,7 @@ const testInputs = { expr: { Atom: "ok", }, - id: 65, + id: 64, span: { start_line: 21, start_column: 4, @@ -5827,7 +9067,7 @@ const testInputs = { expr: { Atom: "true", }, - id: 66, + id: 65, span: { start_line: 21, start_column: 7, @@ -5837,7 +9077,7 @@ const testInputs = { }, ], }, - id: 64, + id: 63, span: { start_line: 21, start_column: 3, diff --git a/traits.ts b/traits.ts index 630b016..7ed57db 100644 --- a/traits.ts +++ b/traits.ts @@ -21,44 +21,6 @@ export const enrichInterfaceWithTraitData = ( ): Map => { const enriched = new Map(); - const enrichListArgs = ( - listArg: any, - functionName: string, - paramMap: any, - path: string[] - ): any => { - const currentPath = [...path, "list"]; - const [traitReferenceName, traitReferenceImport] = getTraitReferenceData( - ast, - functionName, - currentPath - ); - if (traitReferenceName && traitReferenceImport) { - return { - ...listArg, - type: { - trait_reference: { - name: traitReferenceName, - import: traitReferenceImport, - }, - }, - }; - } else if (listArg.type && listArg.type.list) { - return { - ...listArg, - type: { - list: enrichListArgs( - listArg.type.list, - functionName, - paramMap?.list, - currentPath - ), - }, - }; - } - return listArg; - }; - const enrichArgs = ( args: any[], functionName: string, @@ -86,14 +48,42 @@ export const enrichInterfaceWithTraitData = ( list: enrichArgs( [arg.type.list], functionName, - paramMap[arg.name].list, + paramMap[arg.name]?.list, currentPath )[0], }, }; - } else if (paramMap[arg.name]) { + } else if (arg.type && arg.type.response) { + const okPath = [...currentPath, "ok"]; + const errorPath = [...currentPath, "error"]; + const okTraitReference = enrichArgs( + [{ name: "ok", type: arg.type.response.ok }], + functionName, + { ok: paramMap[arg.name]?.response?.ok }, + okPath + )[0]; + const errorTraitReference = enrichArgs( + [{ name: "error", type: arg.type.response.error }], + functionName, + { error: paramMap[arg.name]?.response?.error }, + errorPath + )[0]; + return { + ...arg, + type: { + response: { + ok: okTraitReference.type, + error: errorTraitReference.type, + }, + }, + }; + } else if (paramMap[arg.name] || paramMap.undefined) { const [traitReferenceName, traitReferenceImport] = - getTraitReferenceData(ast, functionName, currentPath); + getTraitReferenceData( + ast, + functionName, + paramMap[arg.name] ? currentPath : path + ); if (traitReferenceName && traitReferenceImport) { return { ...arg, @@ -218,8 +208,27 @@ export const buildTraitReferenceMap = ( if (Object.keys(nestedTraitReferences).length > 0) { traitReferences[arg.name] = { list: nestedTraitReferences }; } + } else if (arg.type && arg.type.response) { + const okTraitReferences = findTraitReferences([arg.type.response.ok]); + const errorTraitReferences = findTraitReferences([ + arg.type.response.error, + ]); + const responseTraitReferences: any = {}; + if (Object.keys(okTraitReferences).length > 0) { + responseTraitReferences.ok = + okTraitReferences[arg.name] || "trait_reference"; + } + if (Object.keys(errorTraitReferences).length > 0) { + responseTraitReferences.error = + errorTraitReferences[arg.name] || "trait_reference"; + } + if (Object.keys(responseTraitReferences).length > 0) { + traitReferences[arg.name] = { response: responseTraitReferences }; + } } else if (arg.type === "trait_reference") { traitReferences[arg.name] = "trait_reference"; + } else if (arg === "trait_reference") { + traitReferences[arg.name] = "trait_reference"; } }); return traitReferences;