Skip to content

Commit

Permalink
[internal] Fixes and Checks: separate into consistency and sanity (tr…
Browse files Browse the repository at this point in the history
…ustwallet#3197)

* rename to sanityFix
* Infra for consistency checks and Fixes.
* Whitelist check moved to consistency check only.

Co-authored-by: Catenocrypt <[email protected]>
  • Loading branch information
optout21 and Catenocrypt authored Aug 10, 2020
1 parent c2807fa commit 294d8bc
Show file tree
Hide file tree
Showing 26 changed files with 250 additions and 69 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/fix-dryrun.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Fixes and Consistency Updates - Dry run
name: Fixes (sanity and consistency) - Dry run
on:
pull_request:
branches: [master]
jobs:
fix-dryrun:
fix-all-dryrun:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/fix.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Fixes and Consistency Updates
name: Fixes
on:
push:
# This runs on fork branches too
branches: [ '*' ]
workflow_dispatch:
jobs:
fix:
fix-all:
runs-on: ubuntu-latest
steps:
- name: Checkout (trustwallet repo, secret token)
Expand All @@ -25,8 +25,12 @@ jobs:
node-version: 12
- name: Install Dependencies
run: npm ci
- name: Run fix script
- name: Run fix script (trustwallet repo, sanity and consistency)
if: github.repository_owner == 'trustwallet'
run: npm run fix
- name: Run fix script (fork repo, sanity only)
if: github.repository_owner != 'trustwallet'
run: npm run fix-sanity
- name: Show fix result (diff); run 'npm run fix' locally
run: |
git status
Expand All @@ -42,4 +46,4 @@ jobs:
with:
commit_user_name: trust-wallet-merge-bot
commit_user_email: [email protected]
commit_message: Fixes and Consistency Updates
commit_message: Fixes (sanity and consistency, auto)
6 changes: 4 additions & 2 deletions .github/workflows/periodic-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ jobs:
run: npm ci
- name: Run scripts
run: npm run update
- name: Show fix result (diff); run 'npm run fix' locally
- name: Show update result (diff)
if: success()
run: git status
run: |
git status
git diff
- name: Run check
run: npm run check
- name: Run test
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pr-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
with:
node-version: '12.x'
- uses: bahmutov/npm-install@v1
- name: Run check
run: npm run check
- name: Run check (sanity only)
run: npm run check-sanity
- name: Run test
run: npm t
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"scripts": {
"test": "jest",
"check": "ts-node ./script/main/check",
"check-sanity": "ts-node ./script/main/check-sanity",
"fix": "ts-node ./script/main/fix",
"fix-sanity": "ts-node ./script/main/fix-sanity",
"update": "ts-node ./script/main/update"
},
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion pricing/coinmarketcap/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { isChecksum } from "../../script/common/eth-web3";
import { isTRC10, isTRC20 } from "../../script/action/tron";
import { retrieveAssetSymbols } from "../../script/action/binance";

export function getChecks(): CheckStepInterface[] {
export function getSanityChecks(): CheckStepInterface[] {
const cmcMap: mapTiker[] = JSON.parse(readFileSync("./pricing/coinmarketcap/mapping.json"));
return [
{
Expand Down
10 changes: 7 additions & 3 deletions pricing/coinmarketcap/cmc-action.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { ActionInterface, CheckStepInterface } from "../../script/action/interface";
import { run } from "./script";
import { getChecks } from "./check";
import { getSanityChecks } from "./check";

export class Coinmarketcap implements ActionInterface {
getName(): string { return "Coinmarketcap mapping"; }

getChecks(): CheckStepInterface[] { return getChecks(); }
getSanityChecks(): CheckStepInterface[] { return getSanityChecks(); }

getConsistencyChecks = null;

fix = null;
sanityFix = null;

consistencyFix = null;

async update(): Promise<void> {
await run();
Expand Down
10 changes: 7 additions & 3 deletions script/action/binance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ async function fetchMissingImages(toFetch: any[]): Promise<string[]> {
export class BinanceAction implements ActionInterface {
getName(): string { return "Binance chain"; }

getChecks(): CheckStepInterface[] {
getSanityChecks(): CheckStepInterface[] {
return [
{
getName: () => { return "Binance chain; assets must exist on chain"},
Expand All @@ -120,8 +120,12 @@ export class BinanceAction implements ActionInterface {
},
];
}

fix = null;

getConsistencyChecks = null;

sanityFix = null;

consistencyFix = null;

async update(): Promise<void> {
// retrieve missing token images; BEP2 (bep8 not supported)
Expand Down
8 changes: 6 additions & 2 deletions script/action/cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { isLowerCase } from "../common/types";
export class CosmosAction implements ActionInterface {
getName(): string { return "Cosmos chain"; }

getChecks(): CheckStepInterface[] {
getSanityChecks(): CheckStepInterface[] {
return [
{
getName: () => { return "Cosmos validator assets must have correct format"},
Expand All @@ -32,7 +32,11 @@ export class CosmosAction implements ActionInterface {
];
}

fix = null;
getConsistencyChecks = null;

sanityFix = null;

consistencyFix = null;

update = null;
}
8 changes: 6 additions & 2 deletions script/action/eth-forks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async function checkAddressChecksums() {
export class EthForks implements ActionInterface {
getName(): string { return "Ethereum forks"; }

getChecks(): CheckStepInterface[] {
getSanityChecks(): CheckStepInterface[] {
var steps: CheckStepInterface[] = [];
ethForkChains.forEach(chain => {
steps.push(
Expand Down Expand Up @@ -105,10 +105,14 @@ export class EthForks implements ActionInterface {
return steps;
}

async fix(): Promise<void> {
getConsistencyChecks = null;

async sanityFix(): Promise<void> {
await formatInfos();
await checkAddressChecksums();
}

consistencyFix = null;

update = null;
}
10 changes: 7 additions & 3 deletions script/action/folders-and-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const foundChains = readDirSync(chainsPath)
export class FoldersFiles implements ActionInterface {
getName(): string { return "Folders and Files"; }

getChecks(): CheckStepInterface[] {
getSanityChecks(): CheckStepInterface[] {
return [
{
getName: () => { return "Repository root dir"},
Expand Down Expand Up @@ -94,7 +94,11 @@ export class FoldersFiles implements ActionInterface {
];
}

fix = null;

getConsistencyChecks = null;

sanityFix = null;

consistencyFix = null;

update = null;
}
16 changes: 13 additions & 3 deletions script/action/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,18 @@ export interface CheckStepInterface {
// An action for a check, fix, or update, or a combination.
export interface ActionInterface {
getName(): string;
// return check steps for check (0, 1, or more)
getChecks(): CheckStepInterface[];
fix(): Promise<void>;
// return check steps for sanity check (0, 1, or more)
getSanityChecks(): CheckStepInterface[];
// return check steps for consistenct check (0, 1, or more)
getConsistencyChecks(): CheckStepInterface[];
sanityFix(): Promise<void>;
consistencyFix(): Promise<void>;
update(): Promise<void>;
}

export enum FixCheckMode {
CheckSanityOnly = 1,
CheckAll,
FixSanityOnly,
FixAll
}
8 changes: 6 additions & 2 deletions script/action/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as bluebird from "bluebird";
export class JsonAction implements ActionInterface {
getName(): string { return "Json files"; }

getChecks(): CheckStepInterface[] {
getSanityChecks(): CheckStepInterface[] {
return [
{
getName: () => { return "Check all JSON files to have valid content"},
Expand All @@ -29,7 +29,11 @@ export class JsonAction implements ActionInterface {
];
}

fix = null;
getConsistencyChecks = null;

sanityFix = null;

consistencyFix = null;

update = null;
}
8 changes: 6 additions & 2 deletions script/action/kava.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { isLowerCase } from "../common/types";
export class KavaAction implements ActionInterface {
getName(): string { return "Kava chain"; }

getChecks(): CheckStepInterface[] {
getSanityChecks(): CheckStepInterface[] {
return [
{
getName: () => { return "Kava validator assets must have correct format"},
Expand All @@ -32,7 +32,11 @@ export class KavaAction implements ActionInterface {
];
}

fix = null;
getConsistencyChecks = null;

sanityFix = null;

consistencyFix = null;

update = null;
}
8 changes: 6 additions & 2 deletions script/action/logo-size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async function checkDownsize(chains, checkOnly: boolean): Promise<string> {
export class LogoSize implements ActionInterface {
getName(): string { return "Logo sizes"; }

getChecks(): CheckStepInterface[] {
getSanityChecks(): CheckStepInterface[] {
return [
{
getName: () => { return "Check that logos are not too large"},
Expand All @@ -91,10 +91,14 @@ export class LogoSize implements ActionInterface {
];
}

async fix(): Promise<void> {
getConsistencyChecks = null;

async sanityFix(): Promise<void> {
const foundChains = readDirSync(chainsPath);
await checkDownsize(foundChains, false);
}

consistencyFix = null;

update = null;
}
8 changes: 6 additions & 2 deletions script/action/terra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { isLowerCase } from "../common/types";
export class TerraAction implements ActionInterface {
getName(): string { return "Terra chain"; }

getChecks(): CheckStepInterface[] {
getSanityChecks(): CheckStepInterface[] {
return [
{
getName: () => { return "Terra validator assets must have correct format"},
Expand All @@ -32,7 +32,11 @@ export class TerraAction implements ActionInterface {
];
}

fix = null;
getConsistencyChecks = null;

sanityFix = null;

consistencyFix = null;

update = null;
}
8 changes: 6 additions & 2 deletions script/action/tezos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async function gen_validators_tezos() {
export class TezosAction implements ActionInterface {
getName(): string { return "Tezos"; }

getChecks(): CheckStepInterface[] {
getSanityChecks(): CheckStepInterface[] {
return [
{
getName: () => { return "Tezos validator assets must have correct format"},
Expand All @@ -96,7 +96,11 @@ export class TezosAction implements ActionInterface {
];
}

fix = null;
getConsistencyChecks = null;

sanityFix = null;

consistencyFix = null;

async update(): Promise<void> {
await gen_validators_tezos();
Expand Down
8 changes: 6 additions & 2 deletions script/action/tron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function isTRC20(address: string): boolean {
export class TronAction implements ActionInterface {
getName(): string { return "Tron chain"; }

getChecks(): CheckStepInterface[] {
getSanityChecks(): CheckStepInterface[] {
return [
{
getName: () => { return "Tron assets should be TRC10 or TRC20, logo of correct size"; },
Expand Down Expand Up @@ -56,7 +56,11 @@ export class TronAction implements ActionInterface {
];
}

fix = null;
getConsistencyChecks = null;

sanityFix = null;

consistencyFix = null;

update = null;
}
Loading

0 comments on commit 294d8bc

Please sign in to comment.