Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug:fix-publish #37

Merged
merged 7 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ name: Publish Packages
on:
pull_request:
types: [closed]
branches:
- main
- development
- beta
- stable

jobs:
publish:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Expand Down
33 changes: 31 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/context/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.nyc_output

22 changes: 22 additions & 0 deletions packages/context/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export default {

// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80
}
},

// Make calling deprecated APIs throw helpful error messages
errorOnDeprecated: false,

// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
maxWorkers: "65%",

// A preset that is used as a base for Jest's configuration
preset: "ts-jest",

};
39 changes: 39 additions & 0 deletions packages/context/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "@skaleproject/context",
"version": "0.0.1",
"description": "SKALE Network Predeployed Context for Chain Information",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"files": [
"lib/*"
],
"devDependencies": {
"@types/jest": "^29.2.3",
"jest": "^29.3.1",
"ts-jest": "^29.0.3"
},
"scripts": {
"build": "tsc --build ./tsconfig.json",
"build:watch": "nodemon --watch \"./src/**/*.*\" --exec npm run build",
"test": "jest --testTimeout=15000",
"test:watch": "jest --watchAll --testTimeout=15000"
},
"repository": {
"directory": "packages/context",
"type": "git",
"url": "git+https://github.com/Dirt-Road-Development/skale.js.git"
},
"keywords": [],
"author": "Sawyer Cutler <sawyer@dirtroad.dev>",
"license": "MIT",
"bugs": {
"url": "https://github.com/Dirt-Road-Development/skale.js/issues"
},
"homepage": "https://github.com/Dirt-Road-Development/skale.js#readme",
"dependencies": {
"@skaleproject/constants": "*",
"@skaleproject/utils": "*",
"ethers": "^5.7.2"
},
"gitHead": "515548f5779ad534a58527e21c0a0f0caca21872"
}
44 changes: 44 additions & 0 deletions packages/context/src/abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[
{
"constant": true,
"inputs": [],
"name": "getSchainName",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "newOwner",
"type": "address"
}
],
"name": "setSchainOwnerAddress",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "getSchainOwnerAddress",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
]
47 changes: 47 additions & 0 deletions packages/context/src/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Addresses } from "@skaleproject/constants/lib/addresses";
import ContextABI from "./abi.json";
import assert from "assert";
import { INewOwner } from "./interfaces";
import { BaseContract, IInitParams } from "@skaleproject/utils/lib/contracts/base_contract";
import { ContractReceipt, utils } from "ethers";

export class Context extends BaseContract {

constructor(params: IInitParams) {
super({
...params,
address: params.address ?? Addresses.Schain.SCHAIN_CONTEXT_ADDRESS,
abi: params.abi ?? ContextABI
});
}

/**
*
* @returns string -> SKALE Chain Name
* @description This value is set when predeployed
*/
public async getSchainName() : Promise<string> {
return await this.contract.getSchainName();
}

/**
*
* @returns string -> owner address
* @description This value can be changed, but is set to Marionette by Deafult
*/
public async getSchainOwnerAddress() : Promise<string> {
return await this.contract.getSchainOwnerAddress();
}

/**
*
* @param params -> The Owner address replacement value
* @returns ContractReceipt of the transaction
*/
public async setSchainOwnerAddress(params: INewOwner) : Promise<ContractReceipt> {
this.checkSigner();
assert(utils.isAddress(params.address), "Invalid Ethereum Address");
const res = await this.contract.setSchainOwnerAddress(params.address);
return res;
}
}
10 changes: 10 additions & 0 deletions packages/context/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
*
* @author Sawyer Cutler
* @license MIT
* @copyright 2022 Dirt Road Dev
* @package @skaleproject/context
*
**/

export * from "./context";
3 changes: 3 additions & 0 deletions packages/context/src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface INewOwner {
address: string;
}
49 changes: 49 additions & 0 deletions packages/context/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Addresses } from "@skaleproject/constants/lib/addresses";
import { ethers, utils, Wallet } from "ethers";
import { Context } from "../src";

const useContext = async({ useSigner }: { useSigner: boolean }) => {
const rng = Wallet.createRandom().connect(new ethers.providers.JsonRpcProvider("https://staging-v2.skalenodes.com/v1/fancy-rasalhague"));

let context: Context;

if (useSigner) {
context = new Context({
signer: rng,
rpcUrl: "https://staging-v2.skalenodes.com/v1/fancy-rasalhague"
});
} else {
context = new Context({
rpcUrl: "https://staging-v2.skalenodes.com/v1/fancy-rasalhague"
});
}

return { context };
}

test("getSchainName() => string", async() => {
const { context } = await useContext({ useSigner: false });
await expect(
context.getSchainName()
).resolves.toEqual("fancy-rasalhague");
})
test("getSchainOwnerAddress() => string", async() => {
const { context } = await useContext({ useSigner: false });
await expect(
context.getSchainOwnerAddress()
).resolves.toEqual(utils.getAddress("0xf63bb14e7e9bd2882957129c3e3197e6d18933b4"));
})
describe("updateOwnerAddress(address: string) => ContractReceipet", () => {
test("updateOwnerAddress(address: string) => ContractReceipt", async() => {
const { context } = await useContext({ useSigner: false });
await expect(
context.setSchainOwnerAddress({ address: Addresses.ZERO_ADDRESS })
).rejects.toThrow("Contract: Not a valid Signer");
})
test("updateOwnerAddress(address: string) => ContractReceipt", async() => {
const { context } = await useContext({ useSigner: true });
await expect(
context.setSchainOwnerAddress({ address: Addresses.ZERO_ADDRESS })
).rejects.toThrow();
})
})
15 changes: 15 additions & 0 deletions packages/context/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"outDir": "./lib/",
"rootDir": "./src"
},
"exclude": [
"./tests/*",
"./coverage/*"
],
"extends": "../../tsconfig.base.json",
"include": [
"./src",
"./tests/*"
]
}
3 changes: 3 additions & 0 deletions tsconfig.package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
{
"path": "./packages/etherbase"
},
{
"path": "./packages/context"
},
{
"path": "./packages/config-controller"
},
Expand Down