@truffle/contract-schema
Advanced tools
Comparing version 3.1.0-ens-events.0 to 3.1.0-tezos.0
54
index.js
@@ -43,2 +43,20 @@ var pkgVersion = require("./package.json").version; | ||
// filter `signature` property from an event | ||
const sanitizeEvent = dirtyEvent => | ||
Object.entries(dirtyEvent).reduce( | ||
(acc, [property, value]) => | ||
property === "signature" | ||
? acc | ||
: Object.assign(acc, { [property]: value }), | ||
{} | ||
); | ||
// sanitize aggregrate events given a `network-object.spec.json#events` object | ||
const sanitizeAllEvents = dirtyEvents => | ||
Object.entries(dirtyEvents).reduce( | ||
(acc, [property, event]) => | ||
Object.assign(acc, { [property]: sanitizeEvent(event) }), | ||
{} | ||
); | ||
var properties = { | ||
@@ -67,2 +85,5 @@ contractName: { | ||
}, | ||
michelson: { | ||
sources: ["michelson"] | ||
}, | ||
bytecode: { | ||
@@ -117,10 +138,28 @@ sources: ["bytecode", "binary", "unlinked_binary", "evm.bytecode.object"], | ||
networks: { | ||
transform: function(value, obj) { | ||
if (value === undefined) { | ||
value = {}; | ||
/** | ||
* Normalize a networks object. Currently this makes sure `events` are | ||
* always sanitized and `links` is extracted when copying from | ||
* a TruffleContract context object. | ||
* | ||
* @param {object} value - the target object | ||
* @param {object | TruffleContract} obj - the context, or source object. | ||
* @return {object} The normalized Network object | ||
*/ | ||
transform: function(value = {}, obj) { | ||
// Sanitize value's events for known networks | ||
Object.keys(value).forEach(networkId => { | ||
if (value[networkId].events) { | ||
value[networkId].events = sanitizeAllEvents(value[networkId].events); | ||
} | ||
}); | ||
// Set and sanitize the current networks property from the | ||
// TruffleContract. Note: obj is a TruffleContract if it has | ||
// `network_id` attribute | ||
const networkId = obj.network_id; | ||
if (networkId && value.hasOwnProperty(networkId)) { | ||
value[networkId].links = obj.links; | ||
value[networkId].events = sanitizeAllEvents(obj.events); | ||
} | ||
if (obj.network_id && value[obj.network_id]) { | ||
value[obj.network_id].events = obj.events; | ||
value[obj.network_id].links = obj.links; | ||
} | ||
return value; | ||
@@ -141,2 +180,3 @@ } | ||
}, | ||
networkType: {}, | ||
devdoc: {}, | ||
@@ -143,0 +183,0 @@ userdoc: {} |
{ | ||
"name": "@truffle/contract-schema", | ||
"version": "3.1.0-ens-events.0", | ||
"description": "JSON schema for contract artifacts", | ||
"license": "MIT", | ||
"author": "Tim Coulter <tim@trufflesuite.com>", | ||
"homepage": "https://github.com/trufflesuite/truffle/tree/master/packages/contract-schema#readme", | ||
"repository": "https://github.com/trufflesuite/truffle/tree/master/packages/contract-schema", | ||
"bugs": { | ||
"url": "https://github.com/trufflesuite/truffle/issues" | ||
}, | ||
"version": "3.1.0-tezos.0", | ||
"main": "index.js", | ||
"typings": "./typings/index.d.ts", | ||
"directories": { | ||
"spec": "./spec" | ||
}, | ||
"scripts": { | ||
"build": "sh ./scripts/generate-declarations", | ||
"prepare": "yarn run build", | ||
"build": "cd spec && json2ts -i contract-object.spec.json -o ./index.d.ts", | ||
"test": "mocha" | ||
}, | ||
"repository": "https://github.com/trufflesuite/truffle/tree/master/packages/contract-schema", | ||
"keywords": [ | ||
"ethereum", | ||
"json", | ||
"schema", | ||
"contract", | ||
"artifacts" | ||
], | ||
"author": "Tim Coulter <tim@trufflesuite.com>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/trufflesuite/truffle/issues" | ||
}, | ||
"homepage": "https://github.com/trufflesuite/truffle/tree/master/packages/contract-schema#readme", | ||
"typings": "./typings/index.d.ts", | ||
"dependencies": { | ||
@@ -34,11 +30,15 @@ "ajv": "^6.10.0", | ||
"mocha": "5.2.0", | ||
"solc": "0.5.0" | ||
"solc": "0.5.16" | ||
}, | ||
"directories": { | ||
"spec": "./spec" | ||
}, | ||
"keywords": [ | ||
"artifacts", | ||
"contract", | ||
"ethereum", | ||
"json", | ||
"schema" | ||
], | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"gitHead": "0327ff65cb9f9cc5641fdad91e6ed0eea2df9f69" | ||
"gitHead": "c2fd8c5e2664a9f8c51fc043a1f7b4b3ab0be2fa" | ||
} |
145
README.md
@@ -10,3 +10,3 @@ # Schema Description: Truffle Contract Object | ||
formally specified<sup>[1](#footnote-1)</sup> JSON object format to represent | ||
Ethereum Virtual Machine (EVM) smart contracts. This representation is intended | ||
supported smart contracts. This representation is intended | ||
to facilitate the use of general purpose smart contract abstractions | ||
@@ -36,6 +36,5 @@ (such as @truffle/contract) by capturing relevant smart contract information in a | ||
<a name="footnote-2">2.</a> Ethereum Contract JSON ABI [https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI#json](https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI#json) | ||
<a name="footnote-2">2.</a> Ethereum Contract JSON ABI [https://solidity.readthedocs.io/en/develop/abi-spec.html](https://solidity.readthedocs.io/en/develop/abi-spec.html). Note: Note: Tezos Contracts do not currently store a functional ABI. | ||
## Properties | ||
@@ -61,2 +60,3 @@ | ||
External programmatic description of contract's interface. The contract's ABI | ||
@@ -68,14 +68,22 @@ determines the means by which applications may interact with individual contract | ||
### `ast` | ||
### `metadata` | ||
| type | _object_ | | ||
| type | _string_ | | ||
| ---: | ---- | | ||
_not included in current version of this specification_ | ||
Abstract Syntax Tree. A nested JSON object representation of contract source | ||
code, as output by compiler. | ||
Contract metadata. Stringified JSON. | ||
### `michelson` | ||
| type | _string_ | | ||
| ---: | ---- | | ||
Tezos instructions that run as part of a contract origination transaction. | ||
Constructor code for a new Tezos contract instance. | ||
Stringified array of JSON. | ||
### `bytecode` | ||
@@ -94,3 +102,2 @@ | ||
### `deployedBytecode` | ||
@@ -109,2 +116,22 @@ | ||
### `sourceMap` | ||
| type | _string_ matching pattern `^[0-9;]*` | | ||
| ---: | ---- | | ||
Source mapping for `bytecode`, pairing contract creation transaction data bytes | ||
with origin statements in uncompiled `source`. | ||
### `deployedSourceMap` | ||
| type | _string_ matching pattern `^[0-9;]*` | | ||
| ---: | ---- | | ||
Source mapping for `deployedBytecode`, pairing contract program data bytes | ||
with origin statements in uncompiled `source`. | ||
### `source` | ||
@@ -124,44 +151,57 @@ | ||
File path for uncompiled source code. | ||
### `sourceMap` | ||
### `ast` | ||
| type | _string_ matching pattern `^[0-9;]*` | | ||
| type | _object_ | | ||
| ---: | ---- | | ||
Source mapping for `bytecode`, pairing contract creation transaction data bytes | ||
with origin statements in uncompiled `source`. | ||
_format not included in current version of this specification_ | ||
Abstract Syntax Tree. A nested JSON object representation of contract source | ||
code, as output by compiler. | ||
### `deployedSourceMap` | ||
| type | _string_ matching pattern `^[0-9;]*` | | ||
### `legacyAST` | ||
| type | _object_ | | ||
| ---: | ---- | | ||
Source mapping for `deployedBytecode`, pairing contract program data bytes | ||
with origin statements in uncompiled `source`. | ||
_format not included in current version of this specification_ | ||
### `schemaVersion` | ||
Legacy Abstract Syntax Tree. A nested JSON object representation of contract source | ||
code, as output by compiler. | ||
| type | _string_ matching pattern `[0-9]+\.[0-9]+\.[0-9]+` | | ||
### `compiler` | ||
| type | _object_ | | ||
| ---: | ---- | | ||
Version of this schema used by contract object representation. | ||
Compiler information. | ||
### `updatedAt` | ||
### `name` | ||
| type | _string_ | | ||
| type | string | | ||
| ---: | ---- | | ||
| format | IS0-8601 Datetime | | ||
Time at which contract object representation was generated/most recently | ||
updated. | ||
Name of the compiler used. | ||
### `version` | ||
| type | string | | ||
| ---: | ---- | | ||
Version of the compiler used. | ||
### `networks` | ||
@@ -172,2 +212,3 @@ | ||
Listing of contract instances. Object mapping network ID keys to network object | ||
@@ -177,2 +218,3 @@ values. Includes address information, links to other contract instances, and/or | ||
#### Properties (key matching `^[a-zA-Z0-9]+$`) | ||
@@ -185,2 +227,50 @@ | ||
### `schemaVersion` | ||
| type | _string_ matching pattern `[0-9]+\.[0-9]+\.[0-9]+` | | ||
| ---: | ---- | | ||
Version of this schema used by contract object representation. | ||
### `updatedAt` | ||
| type | _string_ | | ||
| ---: | ---- | | ||
| format | IS0-8601 Datetime | | ||
Time at which contract object representation was generated/most recently | ||
updated. | ||
### `networkType` | ||
| type | string | | ||
| ---: | ---- | | ||
| default | `"ethereum"` | | ||
Specific blockchain network type targeted. | ||
### `devdoc` | ||
| type | string | | ||
| ---: | ---- | | ||
NatSpec developer documentation of the contract. | ||
### `userdoc` | ||
| type | string | | ||
| ---: | ---- | | ||
NatSpec user documentation of the contract. | ||
## Custom Properties | ||
@@ -193,2 +283,3 @@ | ||
Objects following this schema may include additional properties with | ||
@@ -198,8 +289,5 @@ `x-`-prefixed keys. | ||
## Definitions | ||
### <a name="contract-object--bytecode">Bytecode</a> | ||
@@ -210,2 +298,3 @@ | ||
`0x`-prefixed string representing compiled EVM machine language. | ||
@@ -212,0 +301,0 @@ |
@@ -6,3 +6,2 @@ { | ||
"description": "Describes a contract consumable by Truffle, possibly including deployed instances on networks", | ||
"type": "object", | ||
@@ -19,3 +18,9 @@ "properties": { | ||
}, | ||
"metadata": { "$ref": "#/definitions/Metadata" }, | ||
"metadata": { | ||
"$ref": "#/definitions/Metadata" | ||
}, | ||
"michelson": { | ||
"$ref": "#/definitions/Michelson", | ||
"description": "Michelson sent as Tezos contract-creation transaction data" | ||
}, | ||
"bytecode": { | ||
@@ -37,11 +42,23 @@ "$ref": "#/definitions/Bytecode", | ||
}, | ||
"source": { "$ref": "#/definitions/Source" }, | ||
"sourcePath": { "$ref": "#/definitions/SourcePath" }, | ||
"ast": { "$ref": "#/definitions/AST" }, | ||
"legacyAST": { "$ref": "#/definitions/LegacyAST" }, | ||
"source": { | ||
"$ref": "#/definitions/Source" | ||
}, | ||
"sourcePath": { | ||
"$ref": "#/definitions/SourcePath" | ||
}, | ||
"ast": { | ||
"$ref": "#/definitions/AST" | ||
}, | ||
"legacyAST": { | ||
"$ref": "#/definitions/LegacyAST" | ||
}, | ||
"compiler": { | ||
"type": "object", | ||
"properties": { | ||
"name": {"type": "string"}, | ||
"version": {"type": "string"} | ||
"name": { | ||
"type": "string" | ||
}, | ||
"version": { | ||
"type": "string" | ||
} | ||
} | ||
@@ -51,7 +68,11 @@ }, | ||
"patternProperties": { | ||
"^[a-zA-Z0-9]+$": { "$ref": "network-object.spec.json#" } | ||
"^[a-zA-Z0-9]+$": { | ||
"$ref": "network-object.spec.json#" | ||
} | ||
}, | ||
"additionalProperties": false | ||
}, | ||
"schemaVersion": { "$ref": "#/definitions/SchemaVersion" }, | ||
"schemaVersion": { | ||
"$ref": "#/definitions/SchemaVersion" | ||
}, | ||
"updatedAt": { | ||
@@ -61,4 +82,12 @@ "type": "string", | ||
}, | ||
"devdoc": { "$ref": "#/definitions/NatSpec" }, | ||
"userdoc": { "$ref": "#/definitions/NatSpec" } | ||
"networkType": { | ||
"$ref": "#/definitions/NetworkType", | ||
"default": "ethereum" | ||
}, | ||
"devdoc": { | ||
"$ref": "#/definitions/NatSpec" | ||
}, | ||
"userdoc": { | ||
"$ref": "#/definitions/NatSpec" | ||
} | ||
}, | ||
@@ -69,12 +98,23 @@ "required": [ | ||
"patternProperties": { | ||
"^x-": { "anyOf": [ | ||
{ "type": "string" }, | ||
{ "type": "boolean" }, | ||
{ "type": "number" }, | ||
{ "type": "object" }, | ||
{ "type": "array" } | ||
]} | ||
"^x-": { | ||
"anyOf": [ | ||
{ | ||
"type": "string" | ||
}, | ||
{ | ||
"type": "boolean" | ||
}, | ||
{ | ||
"type": "number" | ||
}, | ||
{ | ||
"type": "object" | ||
}, | ||
{ | ||
"type": "array" | ||
} | ||
] | ||
} | ||
}, | ||
"additionalProperties": false, | ||
"definitions": { | ||
@@ -85,11 +125,14 @@ "ContractName": { | ||
}, | ||
"NatSpec": { | ||
"type": "object" | ||
}, | ||
"Metadata": { | ||
"type": "string" | ||
}, | ||
"Michelson": { | ||
"type": "string" | ||
}, | ||
"NetworkType": { | ||
"type": "string" | ||
}, | ||
"Bytecode": { | ||
@@ -99,7 +142,5 @@ "type": "string", | ||
}, | ||
"Source": { | ||
"type": "string" | ||
}, | ||
"SourceMap": { | ||
@@ -111,15 +152,11 @@ "type": "string", | ||
}, | ||
"SourcePath": { | ||
"type": "string" | ||
}, | ||
"AST": { | ||
"type": "object" | ||
}, | ||
"LegacyAST": { | ||
"type": "object" | ||
}, | ||
"SchemaVersion": { | ||
@@ -126,0 +163,0 @@ "type": "string", |
@@ -0,6 +1,9 @@ | ||
/* tslint:disable */ | ||
/** | ||
* This file was automatically generated by json-schema-to-typescript. | ||
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, | ||
* and run json-schema-to-typescript to regenerate this file. | ||
*/ | ||
* and run `yarn prepare` inside your local packages/contract-schema | ||
* | ||
* @module @truffle/contract-schema/spec | ||
*/ /** */ | ||
@@ -68,3 +71,4 @@ /** | ||
payable?: boolean; | ||
})[]; | ||
} | ||
)[]; | ||
export type Metadata = string; | ||
@@ -86,2 +90,6 @@ export type Source = string; | ||
/** | ||
* Michelson sent as Tezos contract-creation transaction data | ||
*/ | ||
michelson?: string; | ||
/** | ||
* Bytecode sent as contract-creation transaction data, with unresolved link references | ||
@@ -116,2 +124,3 @@ */ | ||
updatedAt?: string; | ||
networkType?: string; | ||
devdoc?: NatSpec; | ||
@@ -118,0 +127,0 @@ userdoc?: NatSpec; |
@@ -1,54 +0,79 @@ | ||
var contract = require("@truffle/contract"); | ||
const contract = require("@truffle/contract"); | ||
var Schema = require("../index.js"); | ||
var assert = require("assert"); | ||
const Schema = require("../index.js"); | ||
const assert = require("assert"); | ||
var MetaCoin = require("./MetaCoin.json"); | ||
const MetaCoin = require("./MetaCoin.json"); | ||
// This file has an invalid json schema for networks with extra `signature` | ||
// property | ||
const MetaCoinInvalid = require("./MetaCoin-invalid.json"); | ||
const validatedMetaCoin = { | ||
"69420": { | ||
address: "0x1111111111111111111111111111111111111111", | ||
events: { | ||
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef": { | ||
anonymous: false, | ||
inputs: [ | ||
{ | ||
indexed: true, | ||
internalType: "address", | ||
name: "_from", | ||
type: "address" | ||
}, | ||
{ | ||
indexed: true, | ||
internalType: "address", | ||
name: "_to", | ||
type: "address" | ||
}, | ||
{ | ||
indexed: false, | ||
internalType: "uint256", | ||
name: "_value", | ||
type: "uint256" | ||
} | ||
], | ||
name: "Transfer", | ||
type: "event" | ||
} | ||
}, | ||
links: { | ||
ConvertLib: "0xB5AF56dF69655d7a68d248EA963eD1416Dd053E2" | ||
}, | ||
transactionHash: | ||
"0x1111111111111111111111111111111111111111111111111111111111111111" | ||
} | ||
}; | ||
const prepareContract = (contract, network) => { | ||
contract.setNetwork(network); | ||
contract.address = "0x1111111111111111111111111111111111111111"; | ||
contract.transactionHash = | ||
"0x1111111111111111111111111111111111111111111111111111111111111111"; | ||
}; | ||
describe("networks", function() { | ||
var MetaCoinContract; | ||
let MetaCoinContractGood, MetaCoinContractBad; | ||
before(() => { | ||
MetaCoinContract = contract(MetaCoin); | ||
MetaCoinContract.setNetwork(9999); | ||
MetaCoinContract.address = "0x1111111111111111111111111111111111111111"; | ||
MetaCoinContract.transactionHash = | ||
"0x1111111111111111111111111111111111111111111111111111111111111111"; | ||
beforeEach(() => { | ||
MetaCoinContractGood = contract(MetaCoin); | ||
prepareContract(MetaCoinContractGood, 69420); | ||
MetaCoinContractBad = contract(MetaCoinInvalid); | ||
prepareContract(MetaCoinContractBad, 69420); | ||
}); | ||
it("normalized has correct events", function() { | ||
var normalized = Schema.normalize(MetaCoinContract); | ||
assert.deepEqual(normalized.networks, { | ||
"9999": { | ||
address: "0x1111111111111111111111111111111111111111", | ||
events: { | ||
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef": { | ||
anonymous: false, | ||
inputs: [ | ||
{ | ||
indexed: true, | ||
name: "_from", | ||
type: "address" | ||
}, | ||
{ | ||
indexed: true, | ||
name: "_to", | ||
type: "address" | ||
}, | ||
{ | ||
indexed: false, | ||
name: "_value", | ||
type: "uint256" | ||
} | ||
], | ||
name: "Transfer", | ||
type: "event" | ||
} | ||
}, | ||
links: {}, | ||
transactionHash: | ||
"0x1111111111111111111111111111111111111111111111111111111111111111" | ||
} | ||
describe("normalized has correct events ", function() { | ||
it("when starting with valid events schema", function() { | ||
const normalized = Schema.normalize(MetaCoinContractGood); | ||
assert.deepEqual(normalized.networks, validatedMetaCoin); | ||
}); | ||
it("when starting with invalid events schema", function() { | ||
const normalized = Schema.normalize(MetaCoinContractBad); | ||
assert.deepEqual(normalized.networks, validatedMetaCoin); | ||
}); | ||
}); | ||
}); |
declare module "@truffle/contract-schema" { | ||
import { ContractObject } from "@truffle/contract-schema/spec"; | ||
export { ContractObject } from "@truffle/contract-schema/spec"; | ||
@@ -8,4 +9,3 @@ namespace Schema { | ||
export type ContractObject = ContractObject; | ||
export default Schema; | ||
} |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
257901
20
6497
292