Skip to content

Commit

Permalink
fix: endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
kylezs committed Dec 15, 2023
1 parent eebc50d commit 4906c83
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 42 deletions.
70 changes: 35 additions & 35 deletions bouncer/commands/read_workspace_tomls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ const projectRoot = process.argv[2];
const engineReleaseVersion = process.argv[3];

export function tomlVersion(cargoFilePath: string): Promise<string> {
return new Promise((resolve, reject) => {
fs.readFile(cargoFilePath, 'utf-8', (err, data) => {
if (err) {
reject(new Error('Error reading file: ' + err.message));
return;
}
return new Promise((resolve, reject) => {
fs.readFile(cargoFilePath, 'utf-8', (err, data) => {
if (err) {
reject(new Error('Error reading file: ' + err.message));
return;
}

try {
const cargoToml = toml.parse(data);
resolve(cargoToml.package.version);
} catch (error) {
reject(new Error('Error parsing TOML: ' + error.message));
}
try {
const cargoToml = toml.parse(data);
resolve(cargoToml.package.version);
} catch (error) {
reject(new Error('Error parsing TOML: ' + error.message));
}
});
});
});
}

const versionRegex = /\d+\.\d+\.\d+/;
Expand All @@ -37,43 +37,43 @@ const nodeTomlVersion = await tomlVersion(`${projectRoot}/state-chain/node/Cargo
const cliTomlVersion = await tomlVersion(`${projectRoot}/api/bin/chainflip-cli/Cargo.toml`);
const lpApiTomlVersion = await tomlVersion(`${projectRoot}/api/bin/chainflip-lp-api/Cargo.toml`);
const brokerTomlVersion = await tomlVersion(
`${projectRoot}/api/bin/chainflip-broker-api/Cargo.toml`,
`${projectRoot}/api/bin/chainflip-broker-api/Cargo.toml`,
);

if (
!(
engineTomlVersion === runtimeTomlVersion &&
runtimeTomlVersion === nodeTomlVersion &&
nodeTomlVersion === cliTomlVersion &&
cliTomlVersion === lpApiTomlVersion &&
lpApiTomlVersion === brokerTomlVersion
)
!(
engineTomlVersion === runtimeTomlVersion &&
runtimeTomlVersion === nodeTomlVersion &&
nodeTomlVersion === cliTomlVersion &&
cliTomlVersion === lpApiTomlVersion &&
lpApiTomlVersion === brokerTomlVersion
)
) {
throw Error('All versions should be the same');
throw Error('All versions should be the same');
} else if (compareSemVer(engineTomlVersion, releaseVersion) === 'greater') {
console.log(
`Binary versions are correct. Your branch has a version greater than the current release.`,
);
console.log(
`Binary versions are correct. Your branch has a version greater than the current release.`,
);
} else {
throw Error(
`Binary versions are incorrect. The version of your branch (${engineTomlVersion}) should be greater than the current release (${releaseVersion}).)`,
);
throw Error(
`Binary versions are incorrect. The version of your branch (${engineTomlVersion}) should be greater than the current release (${releaseVersion}).)`,
);
}

const releaseSpecVersion = Number(
(await jsonRpc('state_getRuntimeVersion', [], 'perseverance.chainflip.xyz', 443)).specVersion,
(await jsonRpc('state_getRuntimeVersion', [], 'https://perseverance.chainflip.xyz:443')).specVersion,
);
console.log(`Release spec version: ${releaseSpecVersion}`);

const specVersionInToml = bumpSpecVersion(`${projectRoot}/state-chain/runtime/src/lib.rs`, true);
console.log(`Spec version in TOML: ${specVersionInToml}`);

if (specVersionInToml >= releaseSpecVersion) {
console.log(
`Spec version is correct. Version in TOML is greater than or equal to the release spec version.`,
);
console.log(
`Spec version is correct. Version in TOML is greater than or equal to the release spec version.`,
);
} else {
throw Error(
`Spec version is incorrect. Version in TOML (${specVersionInToml}) should be greater than or equal to the release spec version (${releaseSpecVersion}).`,
);
throw Error(
`Spec version is incorrect. Version in TOML (${specVersionInToml}) should be greater than or equal to the release spec version (${releaseSpecVersion}).`,
);
}
8 changes: 3 additions & 5 deletions bouncer/shared/json_rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ export async function jsonRpc(
method: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
params: any[],
host?: string,
port?: number,
endpoint?: string,
): Promise<JSON> {
console.log('Sending json RPC', method);

Expand All @@ -16,9 +15,8 @@ export async function jsonRpc(
id,
});

const fetchHost = host ?? 'localhost';
const fetchPort = port ?? 9944;
const response = await fetch(`https://${fetchHost}:${fetchPort}`, {
let fetchEndpoint = endpoint ?? 'http://localhost:9944';
const response = await fetch(`${fetchEndpoint}`, {
method: 'POST',
headers: {
Accept: 'application/json',
Expand Down
3 changes: 1 addition & 2 deletions bouncer/shared/lp_api_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ const testAddress = '0x1594300cbd587694affd70c933b9ee9155b186d9';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async function lpApiRpc(method: string, params: any[]): Promise<any> {
// The port for the lp api is defined in `start_lp_api.sh`
const port = 10589;
return jsonRpc(method, params, undefined, port);
return jsonRpc(method, params, "http://localhost:10589");
}

async function provideLiquidityAndTestAssetBalances() {
Expand Down

0 comments on commit 4906c83

Please sign in to comment.