From a3dedf8224a660a5787165726d39e0acb8c9f41a Mon Sep 17 00:00:00 2001 From: Gabe Rodriguez Date: Fri, 28 Jun 2024 19:19:07 +0200 Subject: [PATCH] Store stakingAssetId as proto-compatible type (#52) --- npm/CHANGELOG.md | 6 ++++++ npm/package.json | 2 +- npm/src/client.test.ts | 10 ++++++++++ npm/src/json.ts | 3 +-- registry/globals.json | 4 +++- tools/compiler/src/processor.rs | 6 +++--- tools/compiler/tests/test_copy_globals.rs | 6 ++---- 7 files changed, 26 insertions(+), 11 deletions(-) diff --git a/npm/CHANGELOG.md b/npm/CHANGELOG.md index c174865..166bd84 100644 --- a/npm/CHANGELOG.md +++ b/npm/CHANGELOG.md @@ -1,5 +1,11 @@ # @penumbra-labs/registry +## 9.2.0 + +### Minor Changes + +- Save stakingAssetId as proto-compatible type + ## 9.1.1 ### Patch Changes diff --git a/npm/package.json b/npm/package.json index f84e292..c51cd8b 100644 --- a/npm/package.json +++ b/npm/package.json @@ -1,6 +1,6 @@ { "name": "@penumbra-labs/registry", - "version": "9.1.1", + "version": "9.2.0", "description": "Chain and asset registry for Penumbra", "main": "./dist/index.js", "module": "./dist/index.mjs", diff --git a/npm/src/client.test.ts b/npm/src/client.test.ts index 8592a99..e489a73 100644 --- a/npm/src/client.test.ts +++ b/npm/src/client.test.ts @@ -1,6 +1,8 @@ import { describe, it, expect } from 'vitest'; import { ChainRegistryClient } from './client'; import { Registry } from './registry'; +import { AssetId } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb'; +import { base64ToUint8Array } from './utils/base64'; describe('ChainRegistryClient', () => { const client = new ChainRegistryClient(); @@ -20,4 +22,12 @@ describe('ChainRegistryClient', () => { expect(registry).toBeInstanceOf(Registry); expect(registry.chainId).toEqual('penumbra-testnet-deimos-7'); }); + + it('returns staking asset global as expected', () => { + const registry = client.globals(); + const umStakingAsset = new AssetId({ + inner: base64ToUint8Array('KeqcLzNx9qSH5+lcJHBB9KNW+YPrBk5dKzvPMiypahA='), + }); + expect(umStakingAsset.equals(registry.stakingAssetId)).toBeTruthy(); + }); }); diff --git a/npm/src/json.ts b/npm/src/json.ts index 11a44bb..ba78df9 100644 --- a/npm/src/json.ts +++ b/npm/src/json.ts @@ -4,7 +4,6 @@ import * as Deimos8 from '../../registry/chains/penumbra-testnet-deimos-8.json'; import * as GlobalsJson from '../../registry/globals.json'; import { Base64AssetId, Chain, Rpc } from './registry'; -import { base64ToUint8Array } from './utils/base64'; import { AssetId } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb'; export interface RegistryGlobals { @@ -53,5 +52,5 @@ export const allJsonRegistries: Record = { export const registryGlobals: RegistryGlobals = { ...GlobalsJson, - stakingAssetId: new AssetId({ inner: base64ToUint8Array(GlobalsJson.stakingAssetId) }), + stakingAssetId: AssetId.fromJson(GlobalsJson.stakingAssetId), }; diff --git a/registry/globals.json b/registry/globals.json index 66d4a3b..4d278f3 100644 --- a/registry/globals.json +++ b/registry/globals.json @@ -13,5 +13,7 @@ "frontends": [ "https://app.testnet.penumbra.zone" ], - "stakingAssetId": "KeqcLzNx9qSH5+lcJHBB9KNW+YPrBk5dKzvPMiypahA=" + "stakingAssetId": { + "inner": "KeqcLzNx9qSH5+lcJHBB9KNW+YPrBk5dKzvPMiypahA=" + } } \ No newline at end of file diff --git a/tools/compiler/src/processor.rs b/tools/compiler/src/processor.rs index d1414f4..c1b155c 100644 --- a/tools/compiler/src/processor.rs +++ b/tools/compiler/src/processor.rs @@ -41,12 +41,12 @@ impl From for Chain { } } -#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Globals { pub rpcs: Vec, pub frontends: Vec, - pub staking_asset_id: String, + pub staking_asset_id: Id, } impl TryFrom for Globals { @@ -56,7 +56,7 @@ impl TryFrom for Globals { Ok(Globals { rpcs: g.rpcs, frontends: g.frontends, - staking_asset_id: base64_id(&STAKING_TOKEN_ASSET_ID)?, + staking_asset_id: *STAKING_TOKEN_ASSET_ID, }) } } diff --git a/tools/compiler/tests/test_copy_globals.rs b/tools/compiler/tests/test_copy_globals.rs index 34aa152..6dde5b0 100644 --- a/tools/compiler/tests/test_copy_globals.rs +++ b/tools/compiler/tests/test_copy_globals.rs @@ -1,3 +1,4 @@ +use penumbra_asset::STAKING_TOKEN_ASSET_ID; use penumbra_registry::parser::{copy_globals, GlobalsInput, Rpc}; use penumbra_registry::processor::Globals; use std::fs::{self, File}; @@ -41,10 +42,7 @@ fn test_successful_copy() { assert_eq!(output_globals.frontends, globals.frontends); assert_eq!(output_globals.rpcs, globals.rpcs); - assert_eq!( - output_globals.staking_asset_id, - "KeqcLzNx9qSH5+lcJHBB9KNW+YPrBk5dKzvPMiypahA=".to_string() - ); + assert_eq!(output_globals.staking_asset_id, *STAKING_TOKEN_ASSET_ID); } #[test]