-
Notifications
You must be signed in to change notification settings - Fork 0
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
initial gatekeeper config cli commands #58
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,59 @@ | ||
import { | ||
confirmationsFlag, | ||
feesFlag, gatekeeperNetworkFlag, | ||
gatewayTokenAddressFlag, | ||
chainFlag, parseFlagsWithPrivateKey, | ||
privateKeyFlag, gasLimitFlag, | ||
gatewayNetworkAddressFlag, | ||
gatekeeperContractAddressFlag, | ||
} from '../utils/oclif/flags' | ||
import {Args, Command, Flags} from '@oclif/core' | ||
import {makeGatekeeperTs} from '../utils/oclif/utils' | ||
import { utils } from 'ethers'; | ||
|
||
export default class UpdateGatekeeperFees extends Command { | ||
static description = 'Update the fee amount a gatekeeper charges on a given network. Can only be changed once every 7 days.'; | ||
|
||
static examples = [ | ||
`$ gateway-eth add-gatekeeper 0x893F4Be53274353CD3379C87C8fd1cb4f8458F94 -n 123 | ||
`, | ||
]; | ||
|
||
static flags = { | ||
help: Flags.help({char: 'h'}), | ||
privateKey: privateKeyFlag(), | ||
gatewayTokenAddress: gatewayTokenAddressFlag(), | ||
gatekeeperNetwork: gatekeeperNetworkFlag(), | ||
gatewayNetworkAddress: gatewayNetworkAddressFlag(), | ||
gatekeeperContractAddress: gatekeeperContractAddressFlag(), | ||
chain: chainFlag(), | ||
fees: feesFlag(), | ||
gasLimit: gasLimitFlag(), | ||
confirmations: confirmationsFlag(), | ||
}; | ||
|
||
static args = { | ||
networkName: Args.string({name: 'networkName', required: true, description: 'Name of the network'}), | ||
issueFee: Args.integer({name: 'issueFee', required: true, description: 'Fee amount on pass issuance'}), | ||
refreshFee: Args.integer({name: 'expireFee', required: true, description: 'Fee amount to refresh an expired token'}), | ||
freezeFee: Args.integer({name: 'freezeFee', required: true, description: 'Fee amount to freeze a pass'}), | ||
expireFee: Args.integer({name: 'expireFee', required: true, description: 'Fee amount to expire a token'}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whitespace |
||
} | ||
|
||
async run(): Promise<void> { | ||
const {args, flags} = await this.parse(UpdateGatekeeperFees) | ||
|
||
const parsedFlags = parseFlagsWithPrivateKey(flags) | ||
|
||
|
||
const gatewayGatekeeperClient = await makeGatekeeperTs(parsedFlags.provider, parsedFlags.privateKey, parsedFlags.gatekeeperContractAddress as string) | ||
const sendableTransaction = await gatewayGatekeeperClient.updateFeeConfig({issueFee: args.issueFee, expireFee: args.expireFee, freezeFee: args.freezeFee, refreshFee: args.refreshFee}, utils.formatBytes32String(args.networkName)) | ||
this.log(`Confirmation is: ${flags.confirmations}`) | ||
const receipt = await sendableTransaction.wait(flags.confirmations) | ||
|
||
this.log( | ||
`Updated gatekeeper fees. TxHash: ${receipt.transactionHash}`, | ||
) | ||
} | ||
} | ||
|
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,70 @@ | ||
import { | ||
confirmationsFlag, | ||
feesFlag, gatekeeperNetworkFlag, | ||
gatewayTokenAddressFlag, | ||
chainFlag, parseFlagsWithPrivateKey, | ||
privateKeyFlag, gasLimitFlag, | ||
gatewayNetworkAddressFlag, | ||
} from '../utils/oclif/flags' | ||
import {Args, Command, Flags} from '@oclif/core' | ||
import {makeDidRegistryClient, makeGatewayNetworkTs} from '../utils/oclif/utils' | ||
import { utils } from 'ethers'; | ||
|
||
export default class UploadGatekeeperConfig extends Command { | ||
static description = 'Uploads issuer.config file to the associated did'; | ||
|
||
static examples = [ | ||
`$ gateway-eth upload-gatekeeper-config 0x893F4Be53274353CD3379C87C8fd1cb4f8458F94 -n 123 | ||
`, | ||
]; | ||
|
||
static flags = { | ||
help: Flags.help({char: 'h'}), | ||
privateKey: privateKeyFlag(), | ||
gatewayTokenAddress: gatewayTokenAddressFlag(), | ||
gatekeeperNetwork: gatekeeperNetworkFlag(), | ||
gatewayNetworkAddress: gatewayNetworkAddressFlag(), | ||
chain: chainFlag(), | ||
fees: feesFlag(), | ||
gasLimit: gasLimitFlag(), | ||
confirmations: confirmationsFlag(), | ||
}; | ||
|
||
static args = { | ||
didRegistryContractAddress: Args.string({name: 'didRegistryContractAddress', required: true, description: 'Contract address of the did registry (currently only support did-bnb)'}), | ||
serviceEndpointUrl: Args.string({name: 'serviceEndpointUrl', required: true, description: 'Url gatekeeper owns that users will be redirected to for token issuance'}) | ||
} | ||
|
||
async run(): Promise<void> { | ||
const {args, flags} = await this.parse(UploadGatekeeperConfig) | ||
|
||
|
||
const parsedFlags = parseFlagsWithPrivateKey(flags) | ||
|
||
const didRegistry = await makeDidRegistryClient(args.didRegistryContractAddress, parsedFlags.privateKey, parsedFlags.provider); | ||
|
||
// Check is did already initialized | ||
const isDidInitialized = didRegistry.isGenerativeDidState(didRegistry.getDid()) | ||
|
||
if(!isDidInitialized) { | ||
this.log(` Initializing did state`) | ||
const initilizeTx = await didRegistry.initializeDidState(); | ||
const initilizeReceipt = await initilizeTx.wait(flags.confirmations); | ||
|
||
this.log(`Initialized did. TxHash: ${initilizeReceipt.transactionHash}`) | ||
} | ||
|
||
const sendableTransaction = await didRegistry.addService({ | ||
fragment: 'gateway-issuer', | ||
service_type: "gateway-issuer", | ||
service_endpoint: args.serviceEndpointUrl | ||
}) | ||
|
||
const receipt = await sendableTransaction.wait(flags.confirmations) | ||
|
||
this.log( | ||
`Added gateway-issuer service endpoint for gatekeeper. TxHash: ${receipt.transactionHash}`, | ||
) | ||
} | ||
} | ||
|
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
68 changes: 68 additions & 0 deletions
68
gatekeeper-cli/src/test/integration/update-gatekeeper-config.spec.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,68 @@ | ||
import { BaseProvider } from "@ethersproject/providers"; | ||
import * as dotenv from "dotenv"; | ||
import { ethers, utils, Wallet } from "ethers"; | ||
import {runCommand} from '@oclif/test' | ||
import { BNB_TESTNET_CONTRACT_ADDRESSES, createRandomString, FOUNDRY_DEFAULT_WALLET_ONE, FOUNDRY_DEFAULT_WALLET_TWO, GATEKEEPER_ON_TESTNET, GatewayNetworkClient, RANDOM_NETWORK_NAME, RANDOM_WALLET, testNetworkName } from "../../utils"; | ||
import assert = require('assert'); | ||
import { GatewayNetworkClass } from "@identity.com/gateway-evm-ts-client/dist/service/GatewayNetwork"; | ||
import { GatewayGatekeeper } from "@identity.com/gateway-evm-ts-client/dist/service/GatewayGatekeeper"; | ||
import "./add-gatekeeper.spec"; | ||
import { DidRegistry } from "@identity.com/did-bnb-client"; | ||
|
||
dotenv.config(); | ||
|
||
describe("Command: Upload gatekeeper service url config", function () { | ||
let provider: BaseProvider; | ||
let gatekeeper: Wallet; | ||
let networkClient: GatewayNetworkClass; | ||
let gatekeeperClient: GatewayGatekeeper; | ||
let networkName: string; | ||
let didRegistry: DidRegistry; | ||
|
||
before("Initialize wallet", async function () { | ||
this.timeout(20000); | ||
provider = new ethers.providers.JsonRpcProvider("http://127.0.0.1:8545"); // Test run against local node forked | ||
|
||
gatekeeper = FOUNDRY_DEFAULT_WALLET_ONE.connect(provider); | ||
networkName = testNetworkName; | ||
networkClient = GatewayNetworkClient(gatekeeper, BNB_TESTNET_CONTRACT_ADDRESSES.gatewayNetwork) | ||
gatekeeperClient = new GatewayGatekeeper(gatekeeper, BNB_TESTNET_CONTRACT_ADDRESSES.gatekeeper); | ||
didRegistry = new DidRegistry(gatekeeper, BNB_TESTNET_CONTRACT_ADDRESSES.didRegistry, { chainEnvironment: "testnet", gasLimit: 500000}); | ||
}); | ||
|
||
it("upload gatekeeper service url config", async function () {; | ||
|
||
let data = await gatekeeperClient.getGatekeeperNetworkData(utils.formatBytes32String(networkName), gatekeeper.address); | ||
|
||
console.log(`Gatekeeper on network ${networkName} : ${JSON.stringify(data)}`); | ||
|
||
const testUrl = `http://${createRandomString(8)}.com`; | ||
|
||
const result = await runCommand([ | ||
"update-gatekeeper-fees", | ||
BNB_TESTNET_CONTRACT_ADDRESSES.didRegistry, | ||
testUrl, | ||
`--privateKey=${gatekeeper.privateKey}`, | ||
`--gatewayKeeperContractAddress=${BNB_TESTNET_CONTRACT_ADDRESSES.gatekeeper}`, | ||
`--chain=localhost` | ||
]) | ||
|
||
|
||
console.log(`output: ${result.stdout}`) | ||
|
||
const wasTxConfirmed = result.stdout.includes("Added gatekeeper to Gateway Token contract. TxHash:") | ||
assert.equal(wasTxConfirmed, true, "Transaction should be confirmed on node") | ||
assert.equal(result.error, undefined, "No errors should occur when creating network") | ||
|
||
let did = await didRegistry.resolve(); | ||
|
||
let containsNewServiceUrl = did.service?.includes({ | ||
id: 'gateway-issuer', | ||
type: "gateway-issuer", | ||
serviceEndpoint: testUrl | ||
}) | ||
|
||
assert.equal(did.service?.length! > 1, true, "gatekeeper should have more than 1 service") | ||
assert.equal(containsNewServiceUrl, true, "gatekeeper should have new service url") | ||
}) | ||
}) |
63 changes: 63 additions & 0 deletions
63
gatekeeper-cli/src/test/integration/update-gatekeeper-fees.spec.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,63 @@ | ||
import { BaseProvider } from "@ethersproject/providers"; | ||
import * as dotenv from "dotenv"; | ||
import { ethers, utils, Wallet } from "ethers"; | ||
import {runCommand} from '@oclif/test' | ||
import { BNB_TESTNET_CONTRACT_ADDRESSES, createRandomString, FOUNDRY_DEFAULT_WALLET_ONE, FOUNDRY_DEFAULT_WALLET_TWO, GATEKEEPER_ON_TESTNET, GatewayNetworkClient, RANDOM_NETWORK_NAME, RANDOM_WALLET, testNetworkName } from "../../utils"; | ||
import assert = require('assert'); | ||
import { GatewayNetworkClass } from "@identity.com/gateway-evm-ts-client/dist/service/GatewayNetwork"; | ||
import { GatewayGatekeeper } from "@identity.com/gateway-evm-ts-client/dist/service/GatewayGatekeeper"; | ||
import "./add-gatekeeper.spec"; | ||
|
||
dotenv.config(); | ||
|
||
describe("Command: Update gatekeeper fee configuration", function () { | ||
let provider: BaseProvider; | ||
let gatekeeper: Wallet; | ||
let networkClient: GatewayNetworkClass; | ||
let gatekeeperClient: GatewayGatekeeper; | ||
let networkName: string; | ||
|
||
before("Initialize wallet", async function () { | ||
this.timeout(20000); | ||
provider = new ethers.providers.JsonRpcProvider("http://127.0.0.1:8545"); // Test run against local node forked | ||
|
||
gatekeeper = FOUNDRY_DEFAULT_WALLET_ONE.connect(provider); | ||
networkName = testNetworkName; | ||
networkClient = GatewayNetworkClient(gatekeeper, BNB_TESTNET_CONTRACT_ADDRESSES.gatewayNetwork) | ||
gatekeeperClient = new GatewayGatekeeper(gatekeeper, BNB_TESTNET_CONTRACT_ADDRESSES.gatekeeper); | ||
}); | ||
|
||
it("update gatekeeper fees for each operation on network", async function () {; | ||
|
||
let data = await gatekeeperClient.getGatekeeperNetworkData(utils.formatBytes32String(networkName), gatekeeper.address); | ||
|
||
console.log(`Gatekeeper on network ${networkName} : ${JSON.stringify(data)}`); | ||
|
||
const result = await runCommand([ | ||
"update-gatekeeper-fees", | ||
networkName, | ||
`2500`, | ||
"2500", | ||
'2500', | ||
`2500`, | ||
`--privateKey=${gatekeeper.privateKey}`, | ||
`--gatewayKeeperContractAddress=${BNB_TESTNET_CONTRACT_ADDRESSES.gatekeeper}`, | ||
`--chain=localhost` | ||
]) | ||
|
||
|
||
console.log(`output: ${result.stdout}`) | ||
|
||
const wasTxConfirmed = result.stdout.includes("Added gatekeeper to Gateway Token contract. TxHash:") | ||
assert.equal(wasTxConfirmed, true, "Transaction should be confirmed on node") | ||
assert.equal(result.error, undefined, "No errors should occur when creating network") | ||
|
||
data = await gatekeeperClient.getGatekeeperNetworkData(utils.formatBytes32String(networkName), gatekeeper.address); | ||
|
||
console.log(JSON.stringify(data)); | ||
|
||
const answer = await networkClient.isGatekeeper(utils.formatBytes32String(networkName), gatekeeper.address); | ||
|
||
assert.equal(answer, true, "gatekeeper should be on network") | ||
}) | ||
}) |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy paste bloops?