Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
feat: add ws endpoint to SubnetRegistrator.sol
Browse files Browse the repository at this point in the history
Signed-off-by: Jawad Tariq <[email protected]>
  • Loading branch information
JDawg287 committed Oct 23, 2023
1 parent ebe9c83 commit 5ceb9fb
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 17 deletions.
12 changes: 8 additions & 4 deletions contracts/topos-core/SubnetRegistrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ contract SubnetRegistrator is Initializable, Ownable {
using Bytes32SetsLib for Bytes32SetsLib.Set;

struct Subnet {
string endpoint;
string httpEndpoint;
string wsEndpoint;
string logoURL;
string name;
string currencySymbol;
Expand Down Expand Up @@ -56,14 +57,16 @@ contract SubnetRegistrator is Initializable, Ownable {
}

/// @notice Register a new subnet
/// @param endpoint JSON RPC endpoint of a subnet
/// @param httpEndpoint JSON RPC http endpoint of a subnet
/// @param wsEndpoint JSON RPC ws endpoint of a subnet
/// @param logoURL URL for the logo of a subnet
/// @param name name of a subnet
/// @param subnetId FROST public key of a subnet
/// @param currencySymbol currencySymbol for a subnet currency
/// @param chainId subnet network ID
function registerSubnet(
string calldata endpoint,
string calldata httpEndpoint,
string calldata wsEndpoint,
string calldata logoURL,
string calldata name,
SubnetId subnetId,
Expand All @@ -72,7 +75,8 @@ contract SubnetRegistrator is Initializable, Ownable {
) public onlyOwner {
subnetSet.insert(SubnetId.unwrap(subnetId));
Subnet storage subnet = subnets[subnetId];
subnet.endpoint = endpoint;
subnet.httpEndpoint = httpEndpoint;
subnet.wsEndpoint = wsEndpoint;
subnet.logoURL = logoURL;
subnet.name = name;
subnet.currencySymbol = currencySymbol;
Expand Down
30 changes: 30 additions & 0 deletions scripts/test/deploy-const-addr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { ContractFactory, Wallet, providers } from 'ethers'

import ConstAddressDeployerJSON from '../../artifacts/contracts/topos-core/ConstAddressDeployer.sol/ConstAddressDeployer.json'

/// function to deploy the constant address deployer
const main = async function (...args: string[]) {
const [providerEndpoint, privateKey] = args
const provider = new providers.JsonRpcProvider(providerEndpoint)
const toposDeployerPrivateKey = sanitizeHexString(privateKey || '')

// deploy the constant address deployer
const wallet = new Wallet(toposDeployerPrivateKey, provider)
const ConstAddressDeployerFactory = new ContractFactory(
ConstAddressDeployerJSON.abi,
ConstAddressDeployerJSON.bytecode,
wallet
)
const ConstAddressDeployer = await ConstAddressDeployerFactory.deploy({
gasLimit: 5_000_000,
})
await ConstAddressDeployer.deployed()
console.log('ConstAddressDeployer deployed to:', ConstAddressDeployer.address)
}

const sanitizeHexString = function (hexString: string) {
return hexString.startsWith('0x') ? hexString : `0x${hexString}`
}

const args = process.argv.slice(2)
main(...args)
39 changes: 26 additions & 13 deletions test/topos-core/SubnetRegistrator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { expect } from 'chai'
describe('SubnetRegistrator', () => {
let subnetRegistrator: Contract

const endpoint = 'http://127.0.0.1'
const httpEndpoint = 'http://127.0.0.1'
const wsEndpoint = 'ws://127.0.0.1'
const logoURL = 'http://image-url.com'
const subnetName = 'Test Subnet'
const subnetId = ethers.utils.formatBytes32String('subnetId')
Expand Down Expand Up @@ -36,7 +37,8 @@ describe('SubnetRegistrator', () => {
subnetRegistrator
.connect(nonAdmin)
.registerSubnet(
endpoint,
httpEndpoint,
wsEndpoint,
logoURL,
subnetName,
subnetId,
Expand All @@ -50,7 +52,8 @@ describe('SubnetRegistrator', () => {
const { admin, subnetRegistrator } =
await deploySubnetRegistratorFixture()
await registerSubnet(
endpoint,
httpEndpoint,
wsEndpoint,
logoURL,
subnetName,
subnetId,
Expand All @@ -61,7 +64,8 @@ describe('SubnetRegistrator', () => {
)
await expect(
registerSubnet(
endpoint,
httpEndpoint,
wsEndpoint,
logoURL,
subnetName,
subnetId,
Expand All @@ -77,7 +81,8 @@ describe('SubnetRegistrator', () => {
const { admin, subnetRegistrator } =
await deploySubnetRegistratorFixture()
await registerSubnet(
endpoint,
httpEndpoint,
wsEndpoint,
logoURL,
subnetName,
subnetId,
Expand All @@ -89,7 +94,8 @@ describe('SubnetRegistrator', () => {
const subnet = await subnetRegistrator.subnets(subnetId)
expect(subnet.name).to.equal(subnetName)
expect(subnet.currencySymbol).to.equal(subnetCurrencySymbol)
expect(subnet.endpoint).to.equal(endpoint)
expect(subnet.httpEndpoint).to.equal(httpEndpoint)
expect(subnet.wsEndpoint).to.equal(wsEndpoint)
expect(subnet.logoURL).to.equal(logoURL)
expect(subnet.chainId).to.equal(chainId)
})
Expand All @@ -98,7 +104,8 @@ describe('SubnetRegistrator', () => {
const { admin, subnetRegistrator } =
await deploySubnetRegistratorFixture()
await registerSubnet(
endpoint,
httpEndpoint,
wsEndpoint,
logoURL,
subnetName,
subnetId,
Expand All @@ -115,7 +122,8 @@ describe('SubnetRegistrator', () => {
const { admin, subnetRegistrator } =
await deploySubnetRegistratorFixture()
await registerSubnet(
endpoint,
httpEndpoint,
wsEndpoint,
logoURL,
subnetName,
subnetId,
Expand All @@ -132,7 +140,8 @@ describe('SubnetRegistrator', () => {
const { admin, subnetRegistrator } =
await deploySubnetRegistratorFixture()
await registerSubnet(
endpoint,
httpEndpoint,
wsEndpoint,
logoURL,
subnetName,
subnetId,
Expand All @@ -150,7 +159,8 @@ describe('SubnetRegistrator', () => {
await deploySubnetRegistratorFixture()
await expect(
registerSubnet(
endpoint,
httpEndpoint,
wsEndpoint,
logoURL,
subnetName,
subnetId,
Expand Down Expand Up @@ -185,7 +195,8 @@ describe('SubnetRegistrator', () => {
const { admin, subnetRegistrator } =
await deploySubnetRegistratorFixture()
await registerSubnet(
endpoint,
httpEndpoint,
wsEndpoint,
logoURL,
subnetName,
subnetId,
Expand All @@ -201,7 +212,8 @@ describe('SubnetRegistrator', () => {
})

async function registerSubnet(
endpoint: string,
httpEndpoint: string,
wsEndpoint: string,
logoURL: string,
subnetName: string,
subnetId: string,
Expand All @@ -213,7 +225,8 @@ describe('SubnetRegistrator', () => {
return await subnetRegistrator
.connect(admin)
.registerSubnet(
endpoint,
httpEndpoint,
wsEndpoint,
logoURL,
subnetName,
subnetId,
Expand Down

0 comments on commit 5ceb9fb

Please sign in to comment.