-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from Web3-API/feat/standardize-web3api-manifest
Feat/standardize web3api manifest
- Loading branch information
Showing
43 changed files
with
929 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"SimpleStorageAddr": "0xe78A0F7E598Cc8b0Bb87894B0F60dD2a88d6a8Ab" | ||
"SimpleStorageAddr": "0xfAa5Bd59B7Be0b06705D8EaED0636288279860b4" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const package = require("../package.json"); | ||
const schemaVersion = package.devDependencies["@web3api/manifest-schema"]; | ||
const schema = require(`@web3api/manifest-schema/formats/${schemaVersion}`); | ||
const { compile } = require("json-schema-to-typescript"); | ||
const { writeFileSync } = require("fs"); | ||
|
||
const generateManifest = () => { | ||
try { | ||
const manifest = schema["manifest"]; | ||
compile(manifest, "Web3API").then((file) => { | ||
const manifestPath = | ||
__dirname + `/../src/manifest/formats/${package.version}.ts`; | ||
writeFileSync(manifestPath, file); | ||
}); | ||
} catch (e) { | ||
console.log("Error generating the Manifest file: ", e); | ||
} | ||
}; | ||
|
||
generateManifest(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import fs from "fs"; | ||
import YAML from "js-yaml"; | ||
|
||
import { | ||
sanitizeAndUpgrade, | ||
upgradeManifest, | ||
ManifestFormats, | ||
} from "../manifest"; | ||
import { Manifest } from "../manifest/formats/0.0.1-alpha.1"; | ||
|
||
describe("Validate web3api manifest ", () => { | ||
it("Should throw file string does not exist error ", async () => { | ||
const manifestPath = | ||
__dirname + "/manifest/validator/file-string-malformed/web3api.yml"; | ||
const manifest = YAML.safeLoad(fs.readFileSync(manifestPath, "utf-8")); | ||
|
||
expect(() => sanitizeAndUpgrade(manifest as Manifest)).toThrowError( | ||
/is not a valid file path. Please use unix style relative paths./ | ||
); | ||
}); | ||
it("Should throw incorrect version format error ", async () => { | ||
const manifestPath = | ||
__dirname + "/manifest/validator/incorrect-version-format/web3api.yml"; | ||
const manifest = YAML.safeLoad(fs.readFileSync(manifestPath, "utf-8")); | ||
|
||
expect(() => sanitizeAndUpgrade(manifest as Manifest)).toThrowError( | ||
/The manifest's format is not correct./ | ||
); | ||
}); | ||
it("Should throw not accepted field error ", async () => { | ||
const manifestPath = | ||
__dirname + "/manifest/validator/not-accepted-field/web3api.yml"; | ||
const manifest = YAML.safeLoad(fs.readFileSync(manifestPath, "utf-8")); | ||
|
||
expect(() => sanitizeAndUpgrade(manifest as Manifest)).toThrowError( | ||
/is not accepted in the schema/ | ||
); | ||
}); | ||
it("Should throw required field missing error ", async () => { | ||
const manifestPath = | ||
__dirname + "/manifest/validator/required-field-missing/web3api.yml"; | ||
const manifest = YAML.safeLoad(fs.readFileSync(manifestPath, "utf-8")); | ||
expect(() => sanitizeAndUpgrade(manifest as Manifest)).toThrowError( | ||
/Missing field:/ | ||
); | ||
}); | ||
it("Should throw wrong type errpr ", async () => { | ||
const manifestPath = | ||
__dirname + "/manifest/validator/wrong-type/web3api.yml"; | ||
const manifest = YAML.safeLoad(fs.readFileSync(manifestPath, "utf-8")); | ||
|
||
expect(() => sanitizeAndUpgrade(manifest as Manifest)).toThrowError( | ||
/has a type error: / | ||
); | ||
}); | ||
}); | ||
|
||
describe("Manifest migration ", () => { | ||
it("Should upgrade 0.0.1-alpha.1 to 0.0.1-alpha.2 ", () => { | ||
const manifestPath = | ||
__dirname + "/manifest/migrator/format-0.0.1-alpha.1/web3api.yml"; | ||
const newManifestPath = | ||
__dirname + "/manifest/migrator/format-0.0.1-alpha.2/web3api.yml"; | ||
const manifest = YAML.safeLoad( | ||
fs.readFileSync(manifestPath, "utf-8") | ||
) as Manifest; | ||
|
||
const manifestGenerated = upgradeManifest( | ||
manifest, | ||
"0.0.1-alpha.2" as ManifestFormats | ||
); | ||
const newManifest = YAML.safeLoad( | ||
fs.readFileSync(newManifestPath, "utf-8") | ||
); | ||
|
||
expect(manifestGenerated).toEqual(newManifest); | ||
}); | ||
|
||
it("Should throw error because is unrecognized format ", () => { | ||
const manifestPath = | ||
__dirname + "/manifest/migrator/unrecognized-format/web3api.yml"; | ||
const manifest = YAML.safeLoad( | ||
fs.readFileSync(manifestPath, "utf-8") | ||
) as Manifest; | ||
expect(() => | ||
upgradeManifest(manifest, "0.0.1-alpha.2" as ManifestFormats) | ||
).toThrowError(/Unrecognized manifest format/); | ||
}); | ||
|
||
it("Should throw error because the from format does not have a migrator", () => { | ||
const manifestPath = | ||
__dirname + "/manifest/migrator/format-0.0.1-alpha.2/web3api.yml"; | ||
const manifest = YAML.safeLoad( | ||
fs.readFileSync(manifestPath, "utf-8") | ||
) as Manifest; | ||
expect(() => | ||
upgradeManifest(manifest, "0.0.1-alpha.3" as ManifestFormats) | ||
).toThrowError(/From format 0.0.1-alpha.2 migrator does not exists/); | ||
}); | ||
|
||
it("Should throw error because to format does not exists in the migrator", () => { | ||
const manifestPath = | ||
__dirname + "/manifest/migrator/format-0.0.1-alpha.1/web3api.yml"; | ||
const manifest = YAML.safeLoad( | ||
fs.readFileSync(manifestPath, "utf-8") | ||
) as Manifest; | ||
expect(() => | ||
upgradeManifest(manifest, "0.0.1-alpha.3" as ManifestFormats) | ||
).toThrowError(/Format to update 0.0.1-alpha.3 is not available in migrator of format 0.0.1-alpha.1/); | ||
}); | ||
}); |
1 change: 1 addition & 0 deletions
1
packages/client-js/src/__tests__/apis/eth-get-put-string/web3api.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
format: 0.0.1-alpha.1 | ||
mutation: | ||
schema: | ||
file: ./src/mutation/schema.graphql | ||
|
1 change: 1 addition & 0 deletions
1
packages/client-js/src/__tests__/apis/ipfs-get-put-string/web3api.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
format: 0.0.1-alpha.1 | ||
mutation: | ||
schema: | ||
file: ./src/mutation/schema.graphql | ||
|
1 change: 1 addition & 0 deletions
1
packages/client-js/src/__tests__/apis/subgraph-query/web3api.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
format: 0.0.1-alpha.1 | ||
mutation: | ||
schema: | ||
file: ./src/mutation/schema.graphql | ||
|
17 changes: 17 additions & 0 deletions
17
packages/client-js/src/__tests__/manifest/migrator/format-0.0.1-alpha.1/web3api.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
description: Awesome Web3API project | ||
format: "0.0.1-alpha.1" | ||
mutation: | ||
schema: | ||
file: ../mutation/schema.graphql | ||
module: | ||
file: ../mutation/index.ts | ||
language: wasm/assemblyscript | ||
query: | ||
schema: | ||
file: ../query/schema.graphql | ||
module: | ||
file: ../query/index.ts | ||
language: wasm/assemblyscript | ||
subgraph: | ||
file: ../subgraph/subgraph.yaml | ||
id: MY_ID |
12 changes: 12 additions & 0 deletions
12
packages/client-js/src/__tests__/manifest/migrator/format-0.0.1-alpha.2/web3api.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
description: Awesome Web3API project | ||
format: "0.0.1-alpha.2" | ||
api: | ||
schemas: | ||
- file: ../query/schema.graphql | ||
- file: ../mutation/schema.graphql | ||
query: | ||
file: ../query/index.ts | ||
language: wasm/assemblyscript | ||
mutation: | ||
file: ../mutation/index.ts | ||
language: wasm/assemblyscript |
5 changes: 5 additions & 0 deletions
5
packages/client-js/src/__tests__/manifest/migrator/src/mutation/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Ethereum } from '@web3api/wasm-ts' | ||
|
||
export function setInformation(): string { | ||
return Ethereum.sendTransaction("0x", "myMethod", ""); | ||
} |
Oops, something went wrong.