mirror of
https://github.com/wharfkit/abicache.git
synced 2026-07-21 17:43:33 +00:00
Initial split from the Session Kit
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"root": true,
|
||||
"ignorePatterns": ["lib/*", "node_modules/**"],
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/eslint-recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:prettier/recommended"
|
||||
],
|
||||
"rules": {
|
||||
"prettier/prettier": "warn",
|
||||
"no-console": "warn",
|
||||
"sort-imports": [
|
||||
"warn",
|
||||
{
|
||||
"ignoreCase": true,
|
||||
"ignoreDeclarationSort": true
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/no-empty-interface": "off", // TODO: This should be removed before PR #1
|
||||
"@typescript-eslint/explicit-module-boundary-types": "off",
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
"@typescript-eslint/no-namespace": "off",
|
||||
"@typescript-eslint/no-non-null-assertion": "off",
|
||||
"@typescript-eslint/no-empty-function": "warn",
|
||||
"no-inner-declarations": "off"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
custom: "https://greymass.com/support-us"
|
||||
@@ -0,0 +1,23 @@
|
||||
name: Tests
|
||||
on: push
|
||||
jobs:
|
||||
test-node-js:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
node-version: [14, 16, 18]
|
||||
name: Node.js v${{ matrix.node-version }}
|
||||
steps:
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
- name: Install dependencies
|
||||
run: make node_modules
|
||||
- name: Run checks
|
||||
run: make check
|
||||
- name: Run tests
|
||||
run: make ci-test
|
||||
@@ -0,0 +1,4 @@
|
||||
node_modules/
|
||||
lib/
|
||||
build/
|
||||
notes.md
|
||||
@@ -0,0 +1,8 @@
|
||||
arrowParens: "always"
|
||||
bracketSpacing: false
|
||||
endOfLine: "lf"
|
||||
printWidth: 100
|
||||
semi: false
|
||||
singleQuote: true
|
||||
tabWidth: 4
|
||||
trailingComma: "es5"
|
||||
@@ -0,0 +1,29 @@
|
||||
Copyright (c) 2023 Greymass Inc. All Rights Reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistribution of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistribution in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
YOU ACKNOWLEDGE THAT THIS SOFTWARE IS NOT DESIGNED, LICENSED OR INTENDED FOR USE
|
||||
IN THE DESIGN, CONSTRUCTION, OPERATION OR MAINTENANCE OF ANY MILITARY FACILITY.
|
||||
@@ -0,0 +1,90 @@
|
||||
SHELL := /bin/bash
|
||||
SRC_FILES := $(shell find src -name '*.ts')
|
||||
TEST_FILES := $(shell find test/tests -name '*.ts')
|
||||
BIN := ./node_modules/.bin
|
||||
MOCHA_OPTS := -u tdd -r ts-node/register -r tsconfig-paths/register --extension ts
|
||||
NYC_OPTS := --temp-dir build/nyc_output --report-dir build/coverage
|
||||
|
||||
lib: ${SRC_FILES} package.json tsconfig.json node_modules rollup.config.js
|
||||
@${BIN}/rollup -c && touch lib
|
||||
|
||||
.PHONY: test
|
||||
test: node_modules
|
||||
@TS_NODE_PROJECT='./test/tsconfig.json' MOCK_DIR='./test/data' \
|
||||
${BIN}/mocha ${MOCHA_OPTS} ${TEST_FILES} --no-timeout --grep '$(grep)'
|
||||
|
||||
test/watch: node_modules
|
||||
@TS_NODE_PROJECT='./test/tsconfig.json' \
|
||||
${BIN}/mocha --watch ${MOCHA_OPTS} ${TEST_FILES} --no-timeout --grep '$(grep)'
|
||||
|
||||
build/coverage: ${SRC_FILES} ${TEST_FILES} node_modules
|
||||
@TS_NODE_PROJECT='./test/tsconfig.json' \
|
||||
${BIN}/nyc ${NYC_OPTS} --reporter=html \
|
||||
${BIN}/mocha ${MOCHA_OPTS} -R nyan ${TEST_FILES}
|
||||
|
||||
.PHONY: coverage
|
||||
coverage: build/coverage
|
||||
@open build/coverage/index.html
|
||||
|
||||
.PHONY: ci-test
|
||||
ci-test: node_modules
|
||||
@TS_NODE_PROJECT='./test/tsconfig.json' MOCK_DIR='./test/data' \
|
||||
${BIN}/nyc ${NYC_OPTS} --reporter=text \
|
||||
${BIN}/mocha ${MOCHA_OPTS} -R list ${TEST_FILES}
|
||||
|
||||
.PHONY: check
|
||||
check: node_modules
|
||||
@${BIN}/eslint src --ext .ts --max-warnings 0 --format unix && echo "Ok"
|
||||
|
||||
.PHONY: format
|
||||
format: node_modules
|
||||
@${BIN}/eslint src --ext .ts --fix
|
||||
|
||||
.PHONY: publish
|
||||
publish: | distclean node_modules
|
||||
@git diff-index --quiet HEAD || (echo "Uncommitted changes, please commit first" && exit 1)
|
||||
@git fetch origin && git diff origin/master --quiet || (echo "Changes not pushed to origin, please push first" && exit 1)
|
||||
@yarn config set version-tag-prefix "" && yarn config set version-git-message "Version %s"
|
||||
@yarn publish && git push && git push --tags
|
||||
|
||||
.PHONY: docs
|
||||
docs: build/docs
|
||||
@open build/docs/index.html
|
||||
|
||||
build/docs: $(SRC_FILES) node_modules
|
||||
@${BIN}/typedoc --out build/docs \
|
||||
--excludeInternal --excludePrivate --excludeProtected \
|
||||
--includeVersion --hideGenerator --readme none \
|
||||
src/index.ts
|
||||
|
||||
build/pages: build/coverage build/docs build/browser.html
|
||||
@mkdir -p build/pages
|
||||
@cp -r build/docs/* build/pages/
|
||||
@cp -r build/coverage build/pages/coverage
|
||||
@cp build/browser.html build/pages/tests.html
|
||||
|
||||
.PHONY: deploy-pages
|
||||
deploy-pages: | clean lib build/pages node_modules
|
||||
@${BIN}/gh-pages -d build/pages
|
||||
|
||||
build/browser.html: $(SRC_FILES) $(TEST_FILES) test/rollup.config.js node_modules
|
||||
@${BIN}/rollup -c test/rollup.config.js
|
||||
|
||||
.PHONY: browser-test
|
||||
browser-test: build/browser.html
|
||||
@open build/browser.html
|
||||
|
||||
node_modules:
|
||||
yarn install --non-interactive --frozen-lockfile --ignore-scripts
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -rf lib/ build/ build/browser.html
|
||||
|
||||
.PHONY: distclean
|
||||
distclean: clean
|
||||
rm -rf node_modules/
|
||||
|
||||
.PHONY: accounts
|
||||
accounts: node_modules
|
||||
${BIN}/ts-node --project test/utils/setup/tsconfig.json test/utils/setup/accounts.ts
|
||||
@@ -0,0 +1,34 @@
|
||||
# @wharfkit/abicache
|
||||
|
||||
An ABI Caching mechanism for Wharf's Contract and Session Kits.
|
||||
|
||||
## Installation
|
||||
|
||||
The `@wharfkit/abicache` package is distributed as a module on npm.
|
||||
|
||||
```
|
||||
yarn add @wharfkit/abicache
|
||||
# or
|
||||
npm install --save @wharfkit/abicache
|
||||
```
|
||||
|
||||
## Developing
|
||||
|
||||
You need [Make](https://www.gnu.org/software/make/), [node.js](https://nodejs.org/en/) and [yarn](https://classic.yarnpkg.com/en/docs/install) installed.
|
||||
|
||||
**All development should be done based on the [dev](https://github.com/wharfkit/session/tree/dev) branch.**
|
||||
|
||||
Clone the repository and run `make` to checkout all dependencies and build the project. The tests can be run using `make test` and can be continously tested during development with `make test/watch`.
|
||||
|
||||
See the [Makefile](./Makefile) for other useful targets.
|
||||
|
||||
Before submitting a pull request make sure to run `make check` and `make format`.
|
||||
|
||||
## Dependencies
|
||||
|
||||
- [@greymass/eosio](https://github.com/greymass/eosio): Core library to provide Antelope data types.
|
||||
- [eosio-signing-request](https://github.com/greymass/eosio-signing-request): Antelope Signing Request Protocol.
|
||||
|
||||
---
|
||||
|
||||
Made with ☕️ & ❤️ by [Greymass](https://greymass.com).
|
||||
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"name": "@wharfkit/abicache",
|
||||
"description": "ABI Caching Mechanism for use in Session and Contract Kits",
|
||||
"version": "1.0.0",
|
||||
"homepage": "https://github.com/wharfkit/abicache",
|
||||
"license": "BSD-3-Clause",
|
||||
"main": "lib/abicache.js",
|
||||
"module": "lib/abicache.m.js",
|
||||
"types": "lib/abicache.d.ts",
|
||||
"unpkg": "lib/abicache.bundle.js",
|
||||
"sideEffects": false,
|
||||
"files": [
|
||||
"lib/*",
|
||||
"src/*"
|
||||
],
|
||||
"scripts": {
|
||||
"prepare": "make"
|
||||
},
|
||||
"dependencies": {
|
||||
"@greymass/eosio": "^0.6.10",
|
||||
"eosio-signing-request": "^2.5.3",
|
||||
"pako": "^2.0.4",
|
||||
"tslib": "^2.1.0"
|
||||
},
|
||||
"resolutions": {
|
||||
"@greymass/eosio": "^0.6.10"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/preset-env": "^7.20.2",
|
||||
"@rollup/plugin-alias": "^3.1.4",
|
||||
"@rollup/plugin-babel": "^6.0.3",
|
||||
"@rollup/plugin-commonjs": "^22.0.0",
|
||||
"@rollup/plugin-json": "^4.1.0",
|
||||
"@rollup/plugin-node-resolve": "^14.1.0",
|
||||
"@rollup/plugin-replace": "^5.0.1",
|
||||
"@rollup/plugin-typescript": "^10.0.1",
|
||||
"@rollup/plugin-virtual": "^2.0.3",
|
||||
"@types/chai": "^4.3.1",
|
||||
"@types/mocha": "^9.0.0",
|
||||
"@types/node": "^18.7.18",
|
||||
"@typescript-eslint/eslint-plugin": "^5.20.0",
|
||||
"@typescript-eslint/parser": "^5.20.0",
|
||||
"@wharfkit/mock-data": "^1.0.0-beta10",
|
||||
"@wharfkit/wallet-plugin-privatekey": "^0.5.0",
|
||||
"chai": "^4.3.4",
|
||||
"eslint": "^8.13.0",
|
||||
"eslint-config-prettier": "^8.1.0",
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"gh-pages": "^4.0.0",
|
||||
"mocha": "^10.0.0",
|
||||
"node-fetch": "^2.6.1",
|
||||
"nyc": "^15.1.0",
|
||||
"prettier": "^2.2.1",
|
||||
"rollup": "^2.70.2",
|
||||
"rollup-plugin-cleanup": "^3.2.1",
|
||||
"rollup-plugin-dts": "^4.2.1",
|
||||
"rollup-plugin-terser": "^7.0.2",
|
||||
"ts-node": "^10.9.1",
|
||||
"tsconfig-paths": "^4.1.1",
|
||||
"typedoc": "^0.23.14",
|
||||
"typedoc-plugin-mermaid": "^1.10.0",
|
||||
"typescript": "^4.1.2",
|
||||
"yarn-deduplicate": "^6.0.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import dts from 'rollup-plugin-dts'
|
||||
import typescript from '@rollup/plugin-typescript'
|
||||
import cleanup from 'rollup-plugin-cleanup'
|
||||
import pkg from './package.json'
|
||||
|
||||
const external = Object.keys(pkg.dependencies)
|
||||
|
||||
/** @type {import('rollup').RollupOptions} */
|
||||
export default [
|
||||
{
|
||||
input: 'src/index.ts',
|
||||
output: {
|
||||
file: pkg.main,
|
||||
format: 'cjs',
|
||||
sourcemap: true,
|
||||
exports: 'named',
|
||||
},
|
||||
plugins: [typescript({target: 'es6'}), cleanup({extensions: ['js', 'ts']})],
|
||||
external,
|
||||
},
|
||||
{
|
||||
input: 'src/index.ts',
|
||||
output: {
|
||||
file: pkg.module,
|
||||
format: 'esm',
|
||||
sourcemap: true,
|
||||
},
|
||||
plugins: [typescript({target: 'es2020'}), cleanup({extensions: ['js', 'ts']})],
|
||||
external,
|
||||
},
|
||||
{
|
||||
input: 'src/index.ts',
|
||||
output: {file: pkg.types, format: 'esm'},
|
||||
plugins: [dts(), cleanup({extensions: ['d.ts']})],
|
||||
},
|
||||
]
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
import {ABI, ABIDef, API, APIClient, NameType} from '@greymass/eosio'
|
||||
import {AbiProvider} from 'eosio-signing-request'
|
||||
|
||||
export interface ABICacheInterface extends AbiProvider {
|
||||
readonly cache: Map<string, ABI>
|
||||
readonly pending: Map<string, Promise<API.v1.GetAbiResponse>>
|
||||
getAbi(account: NameType): Promise<ABI>
|
||||
setAbi(account: NameType, abi: ABIDef): void
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an APIClient instance, this class provides an AbiProvider interface for retrieving and caching ABIs.
|
||||
*/
|
||||
export class ABICache implements ABICacheInterface {
|
||||
readonly cache: Map<string, ABI> = new Map()
|
||||
readonly pending: Map<string, Promise<API.v1.GetAbiResponse>> = new Map()
|
||||
|
||||
constructor(readonly client: APIClient) {}
|
||||
|
||||
async getAbi(account: NameType): Promise<ABI> {
|
||||
const key = String(account)
|
||||
let record = this.cache.get(key)
|
||||
if (!record) {
|
||||
let getAbi = this.pending.get(key)
|
||||
if (!getAbi) {
|
||||
getAbi = this.client.v1.chain.get_abi(account)
|
||||
this.pending.set(key, getAbi)
|
||||
}
|
||||
const response = await getAbi
|
||||
this.pending.delete(key)
|
||||
if (response.abi) {
|
||||
record = ABI.from(response.abi)
|
||||
this.cache.set(key, record)
|
||||
} else {
|
||||
throw new Error(`ABI for ${key} could not be loaded.`)
|
||||
}
|
||||
}
|
||||
return record
|
||||
}
|
||||
|
||||
setAbi(account: NameType, abi: ABIDef) {
|
||||
const key = String(account)
|
||||
this.cache.set(key, ABI.from(abi))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import * as pkg from './index'
|
||||
const ABICache = pkg.default
|
||||
for (const key of Object.keys(pkg)) {
|
||||
if (key === 'default') continue
|
||||
ABICache[key] = pkg[key]
|
||||
}
|
||||
export default ABICache
|
||||
@@ -0,0 +1 @@
|
||||
export * from './abi'
|
||||
@@ -0,0 +1,6 @@
|
||||
// export library
|
||||
export * from './index-module'
|
||||
|
||||
// default export is Session class for convenience
|
||||
import {ABICache} from './index-module'
|
||||
export default ABICache
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,201 @@
|
||||
{
|
||||
"request": {
|
||||
"path": "https://jungle4.greymass.com/v1/chain/get_abi",
|
||||
"params": {
|
||||
"method": "POST",
|
||||
"body": "{\"account_name\":\"eosio.token\"}"
|
||||
}
|
||||
},
|
||||
"status": 200,
|
||||
"json": {
|
||||
"account_name": "eosio.token",
|
||||
"abi": {
|
||||
"version": "eosio::abi/1.2",
|
||||
"types": [],
|
||||
"structs": [
|
||||
{
|
||||
"name": "account",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "balance",
|
||||
"type": "asset"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "close",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "owner",
|
||||
"type": "name"
|
||||
},
|
||||
{
|
||||
"name": "symbol",
|
||||
"type": "symbol"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "create",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "issuer",
|
||||
"type": "name"
|
||||
},
|
||||
{
|
||||
"name": "maximum_supply",
|
||||
"type": "asset"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "currency_stats",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "supply",
|
||||
"type": "asset"
|
||||
},
|
||||
{
|
||||
"name": "max_supply",
|
||||
"type": "asset"
|
||||
},
|
||||
{
|
||||
"name": "issuer",
|
||||
"type": "name"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "issue",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "to",
|
||||
"type": "name"
|
||||
},
|
||||
{
|
||||
"name": "quantity",
|
||||
"type": "asset"
|
||||
},
|
||||
{
|
||||
"name": "memo",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "open",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "owner",
|
||||
"type": "name"
|
||||
},
|
||||
{
|
||||
"name": "symbol",
|
||||
"type": "symbol"
|
||||
},
|
||||
{
|
||||
"name": "ram_payer",
|
||||
"type": "name"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "retire",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "quantity",
|
||||
"type": "asset"
|
||||
},
|
||||
{
|
||||
"name": "memo",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "transfer",
|
||||
"base": "",
|
||||
"fields": [
|
||||
{
|
||||
"name": "from",
|
||||
"type": "name"
|
||||
},
|
||||
{
|
||||
"name": "to",
|
||||
"type": "name"
|
||||
},
|
||||
{
|
||||
"name": "quantity",
|
||||
"type": "asset"
|
||||
},
|
||||
{
|
||||
"name": "memo",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"actions": [
|
||||
{
|
||||
"name": "close",
|
||||
"type": "close",
|
||||
"ricardian_contract": ""
|
||||
},
|
||||
{
|
||||
"name": "create",
|
||||
"type": "create",
|
||||
"ricardian_contract": ""
|
||||
},
|
||||
{
|
||||
"name": "issue",
|
||||
"type": "issue",
|
||||
"ricardian_contract": ""
|
||||
},
|
||||
{
|
||||
"name": "open",
|
||||
"type": "open",
|
||||
"ricardian_contract": ""
|
||||
},
|
||||
{
|
||||
"name": "retire",
|
||||
"type": "retire",
|
||||
"ricardian_contract": ""
|
||||
},
|
||||
{
|
||||
"name": "transfer",
|
||||
"type": "transfer",
|
||||
"ricardian_contract": ""
|
||||
}
|
||||
],
|
||||
"tables": [
|
||||
{
|
||||
"name": "accounts",
|
||||
"index_type": "i64",
|
||||
"key_names": [],
|
||||
"key_types": [],
|
||||
"type": "account"
|
||||
},
|
||||
{
|
||||
"name": "stat",
|
||||
"index_type": "i64",
|
||||
"key_names": [],
|
||||
"key_types": [],
|
||||
"type": "currency_stats"
|
||||
}
|
||||
],
|
||||
"ricardian_clauses": [],
|
||||
"error_messages": [],
|
||||
"abi_extensions": [],
|
||||
"variants": [],
|
||||
"action_results": []
|
||||
}
|
||||
},
|
||||
"text": "{\"account_name\":\"eosio.token\",\"abi\":{\"version\":\"eosio::abi/1.2\",\"types\":[],\"structs\":[{\"name\":\"account\",\"base\":\"\",\"fields\":[{\"name\":\"balance\",\"type\":\"asset\"}]},{\"name\":\"close\",\"base\":\"\",\"fields\":[{\"name\":\"owner\",\"type\":\"name\"},{\"name\":\"symbol\",\"type\":\"symbol\"}]},{\"name\":\"create\",\"base\":\"\",\"fields\":[{\"name\":\"issuer\",\"type\":\"name\"},{\"name\":\"maximum_supply\",\"type\":\"asset\"}]},{\"name\":\"currency_stats\",\"base\":\"\",\"fields\":[{\"name\":\"supply\",\"type\":\"asset\"},{\"name\":\"max_supply\",\"type\":\"asset\"},{\"name\":\"issuer\",\"type\":\"name\"}]},{\"name\":\"issue\",\"base\":\"\",\"fields\":[{\"name\":\"to\",\"type\":\"name\"},{\"name\":\"quantity\",\"type\":\"asset\"},{\"name\":\"memo\",\"type\":\"string\"}]},{\"name\":\"open\",\"base\":\"\",\"fields\":[{\"name\":\"owner\",\"type\":\"name\"},{\"name\":\"symbol\",\"type\":\"symbol\"},{\"name\":\"ram_payer\",\"type\":\"name\"}]},{\"name\":\"retire\",\"base\":\"\",\"fields\":[{\"name\":\"quantity\",\"type\":\"asset\"},{\"name\":\"memo\",\"type\":\"string\"}]},{\"name\":\"transfer\",\"base\":\"\",\"fields\":[{\"name\":\"from\",\"type\":\"name\"},{\"name\":\"to\",\"type\":\"name\"},{\"name\":\"quantity\",\"type\":\"asset\"},{\"name\":\"memo\",\"type\":\"string\"}]}],\"actions\":[{\"name\":\"close\",\"type\":\"close\",\"ricardian_contract\":\"\"},{\"name\":\"create\",\"type\":\"create\",\"ricardian_contract\":\"\"},{\"name\":\"issue\",\"type\":\"issue\",\"ricardian_contract\":\"\"},{\"name\":\"open\",\"type\":\"open\",\"ricardian_contract\":\"\"},{\"name\":\"retire\",\"type\":\"retire\",\"ricardian_contract\":\"\"},{\"name\":\"transfer\",\"type\":\"transfer\",\"ricardian_contract\":\"\"}],\"tables\":[{\"name\":\"accounts\",\"index_type\":\"i64\",\"key_names\":[],\"key_types\":[],\"type\":\"account\"},{\"name\":\"stat\",\"index_type\":\"i64\",\"key_names\":[],\"key_types\":[],\"type\":\"currency_stats\"}],\"ricardian_clauses\":[],\"error_messages\":[],\"abi_extensions\":[],\"variants\":[],\"action_results\":[]}}"
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
/* eslint-disable no-undef */
|
||||
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
import {terser} from 'rollup-plugin-terser'
|
||||
import alias from '@rollup/plugin-alias'
|
||||
import commonjs from '@rollup/plugin-commonjs'
|
||||
import json from '@rollup/plugin-json'
|
||||
import replace from '@rollup/plugin-replace'
|
||||
import resolve from '@rollup/plugin-node-resolve'
|
||||
import typescript from '@rollup/plugin-typescript'
|
||||
import virtual from '@rollup/plugin-virtual'
|
||||
|
||||
const mockData = Object.fromEntries(
|
||||
fs
|
||||
.readdirSync(path.join(__dirname, 'data'))
|
||||
.map((f) => path.join(__dirname, 'data', f))
|
||||
.map((f) => [path.basename(f), JSON.parse(fs.readFileSync(f))])
|
||||
)
|
||||
|
||||
const testFiles = fs
|
||||
.readdirSync(path.join(__dirname, 'tests'))
|
||||
.filter((f) => f.match(/\.ts$/))
|
||||
.map((f) => path.join(__dirname, 'tests', f))
|
||||
.sort()
|
||||
|
||||
const template = `
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Tests</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link rel="stylesheet" href="https://unpkg.com/mocha/mocha.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="mocha"></div>
|
||||
<script src="https://unpkg.com/chai/chai.js"></script>
|
||||
<script src="https://unpkg.com/mocha/mocha.js"></script>
|
||||
<script class="mocha-init">
|
||||
mocha.setup('tdd');
|
||||
mocha.checkLeaks();
|
||||
</script>
|
||||
<script>%%tests%%</script>
|
||||
<script class="mocha-exec">
|
||||
mocha.run();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
|
||||
function inline() {
|
||||
return {
|
||||
name: 'Inliner',
|
||||
generateBundle(opts, bundle) {
|
||||
const file = path.basename(opts.file)
|
||||
const output = bundle[file]
|
||||
delete bundle[file]
|
||||
const code = `${output.code}`
|
||||
this.emitFile({
|
||||
type: 'asset',
|
||||
fileName: file,
|
||||
source: template.replace('%%tests%%', code),
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/** @type {import('rollup').RollupOptions} */
|
||||
export default [
|
||||
{
|
||||
input: 'tests.ts',
|
||||
output: {
|
||||
file: 'build/browser.html',
|
||||
format: 'iife',
|
||||
sourcemap: true,
|
||||
globals: {
|
||||
chai: 'chai',
|
||||
mocha: 'mocha',
|
||||
util: 'undefined',
|
||||
crypto: 'undefined',
|
||||
},
|
||||
},
|
||||
external: ['chai', 'mocha', 'crypto', 'util'],
|
||||
plugins: [
|
||||
virtual({
|
||||
'tests.ts': testFiles.map((f) => `import '${f.slice(0, -3)}'`).join('\n'),
|
||||
}),
|
||||
alias({
|
||||
entries: [
|
||||
{find: '$lib', replacement: path.join(__dirname, '..', 'lib/abicache.m.js')},
|
||||
{
|
||||
find: '@wharfkit/mock-data',
|
||||
replacement: './test/utils/browser-fetch.ts',
|
||||
},
|
||||
],
|
||||
}),
|
||||
typescript({target: 'es6', module: 'esnext', tsconfig: './test/tsconfig.json'}),
|
||||
replace({'global.MOCK_DATA': JSON.stringify(mockData), preventAssignment: true}),
|
||||
resolve({browser: true}),
|
||||
commonjs(),
|
||||
json(),
|
||||
terser({
|
||||
mangle: false,
|
||||
format: {
|
||||
beautify: true,
|
||||
},
|
||||
compress: false,
|
||||
}),
|
||||
inline(),
|
||||
],
|
||||
},
|
||||
]
|
||||
@@ -0,0 +1,53 @@
|
||||
import {makeClient} from '@wharfkit/mock-data'
|
||||
import {ABI, Name} from '@greymass/eosio'
|
||||
import {assert} from 'chai'
|
||||
import {ABICache} from '$lib'
|
||||
|
||||
const client = makeClient()
|
||||
|
||||
suite('ABICache', function () {
|
||||
let abiCache = new ABICache(client)
|
||||
setup(function () {
|
||||
abiCache = new ABICache(client)
|
||||
})
|
||||
test('constructor', function () {
|
||||
assert.instanceOf(abiCache, ABICache)
|
||||
})
|
||||
test('fetches data', async function () {
|
||||
const result = await abiCache.getAbi(Name.from('eosio.token'))
|
||||
assert.instanceOf(result, ABI)
|
||||
assert.equal(result.version, 'eosio::abi/1.2')
|
||||
})
|
||||
test('caches data', async function () {
|
||||
await abiCache.getAbi(Name.from('eosio.evm'))
|
||||
assert.isTrue(abiCache.cache.has('eosio.evm'))
|
||||
await abiCache.getAbi(Name.from('eosio.token'))
|
||||
assert.isTrue(abiCache.cache.has('eosio.token'))
|
||||
})
|
||||
test('no duplicate data', async function () {
|
||||
await abiCache.getAbi(Name.from('eosio.token'))
|
||||
await abiCache.getAbi(Name.from('eosio.token'))
|
||||
assert.isTrue(abiCache.cache.has('eosio.token'))
|
||||
assert.equal(abiCache.cache.size, 1)
|
||||
})
|
||||
test('manually add abi', async function () {
|
||||
const abi = ABI.from({version: 'eosio::abi/1.2'})
|
||||
abiCache.setAbi('foo', abi)
|
||||
assert.equal(abiCache.cache.size, 1)
|
||||
assert.instanceOf(abiCache.cache.get('foo'), ABI)
|
||||
assert.equal(abi.version, 'eosio::abi/1.2')
|
||||
const result = await abiCache.getAbi(Name.from('foo'))
|
||||
assert.instanceOf(result, ABI)
|
||||
assert.equal(result.version, 'eosio::abi/1.2')
|
||||
})
|
||||
test('manually add struct', async function () {
|
||||
// @Struct.type('transfer')
|
||||
// class Transfer extends Struct {
|
||||
// @Struct.field(Name) from!: Name
|
||||
// @Struct.field(Name) to!: Name
|
||||
// @Struct.field(Asset) quantity!: Asset
|
||||
// @Struct.field('string') memo!: string
|
||||
// }
|
||||
// abiCache.addStruct(Transfer)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"isolatedModules": false,
|
||||
"resolveJsonModule": true,
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"types": ["mocha", "node"],
|
||||
"baseUrl": "..",
|
||||
"paths": {
|
||||
"@wharfkit/abicache": ["src"],
|
||||
"$lib": ["src"],
|
||||
"$test": ["test"],
|
||||
"$test/*": ["test/*"]
|
||||
}
|
||||
},
|
||||
"include": ["*.ts", "**/*.ts"]
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"downlevelIteration": true,
|
||||
"esModuleInterop": true,
|
||||
"experimentalDecorators": true,
|
||||
"importHelpers": true,
|
||||
"isolatedModules": true,
|
||||
"lib": ["dom", "es2020"],
|
||||
"module": "es2020",
|
||||
"moduleResolution": "node",
|
||||
"noImplicitAny": false,
|
||||
"sourceMap": true,
|
||||
"strict": true,
|
||||
"target": "es2020"
|
||||
},
|
||||
"include": ["src/**/*"]
|
||||
}
|
||||
Reference in New Issue
Block a user