diff --git a/src/smartcontracts/typesystem/endpoint.spec.ts b/src/smartcontracts/typesystem/endpoint.spec.ts new file mode 100644 index 00000000..8a596b14 --- /dev/null +++ b/src/smartcontracts/typesystem/endpoint.spec.ts @@ -0,0 +1,19 @@ +import { assert } from "chai"; +import { EndpointDefinition } from "./endpoint"; + + +describe("test endpoint", () => { + it('should handle an only-owner modifier', async () => { + const actual = EndpointDefinition.fromJSON({ + name: 'foo', + ownerOnly: true, + mutability: 'payable', + payableInTokens: [], + inputs: [], + outputs: [], + }) + + assert.isTrue(actual.modifiers.ownerOnly) + assert.isTrue(actual.modifiers.isOwnerOnly()) + }) +}); diff --git a/src/smartcontracts/typesystem/endpoint.ts b/src/smartcontracts/typesystem/endpoint.ts index f7cfacd1..21f295da 100644 --- a/src/smartcontracts/typesystem/endpoint.ts +++ b/src/smartcontracts/typesystem/endpoint.ts @@ -23,19 +23,21 @@ export class EndpointDefinition { static fromJSON(json: { name: string, + ownerOnly?: boolean mutability: string, payableInTokens: string[], inputs: any[], outputs: any[] }): EndpointDefinition { json.name = json.name == null ? NamePlaceholder : json.name; + json.ownerOnly = json.ownerOnly || false; json.payableInTokens = json.payableInTokens || []; json.inputs = json.inputs || []; json.outputs = json.outputs || []; let input = json.inputs.map(param => EndpointParameterDefinition.fromJSON(param)); let output = json.outputs.map(param => EndpointParameterDefinition.fromJSON(param)); - let modifiers = new EndpointModifiers(json.mutability, json.payableInTokens); + let modifiers = new EndpointModifiers(json.mutability, json.payableInTokens, json.ownerOnly); return new EndpointDefinition(json.name, input, output, modifiers); } @@ -44,10 +46,12 @@ export class EndpointDefinition { export class EndpointModifiers { readonly mutability: string; readonly payableInTokens: string[]; + readonly ownerOnly: boolean; - constructor(mutability: string, payableInTokens: string[]) { + constructor(mutability: string, payableInTokens: string[], ownerOnly?: boolean) { this.mutability = mutability || ""; this.payableInTokens = payableInTokens || []; + this.ownerOnly = ownerOnly || false; } isPayableInEGLD(): boolean { @@ -77,6 +81,10 @@ export class EndpointModifiers { isReadonly() { return this.mutability == "readonly"; } + + isOwnerOnly() { + return this.ownerOnly; + } } export class EndpointParameterDefinition {