Skip to content

Commit

Permalink
Remove Check Handle RPC for now
Browse files Browse the repository at this point in the history
  • Loading branch information
wilwade committed Dec 20, 2024
1 parent 733e555 commit cc2b81b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 80 deletions.
25 changes: 4 additions & 21 deletions e2e/handles/handles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('🤝 Handles', function () {
assert.equal(msaFromHandle.toString(), msa_id.toString(), 'msaFromHandle should be equal to msa_id');

// Check that the rpc returns the index as > 0
const apiCheck = await ExtrinsicHelper.apiPromise.rpc.handles.checkHandle(handle);
const apiCheck = await ExtrinsicHelper.apiPromise.call.handlesRuntimeApi.checkHandle(handle);
assert(apiCheck.suffix_index > 0);
});
});
Expand Down Expand Up @@ -173,7 +173,7 @@ describe('🤝 Handles', function () {

describe('checkHandle basic test', function () {
it('expected outcome for a good handle', async function () {
const res = await ExtrinsicHelper.apiPromise.rpc.handles.checkHandle('Little Bobby Tables');
const res = await ExtrinsicHelper.apiPromise.call.handlesRuntimeApi.checkHandle('Little Bobby Tables');
assert(!res.isEmpty, 'Expected a response');
assert.deepEqual(res.toHuman(), {
base_handle: 'Little Bobby Tables',
Expand All @@ -185,7 +185,7 @@ describe('🤝 Handles', function () {
});

it('expected outcome for a bad handle', async function () {
const res = await ExtrinsicHelper.apiPromise.rpc.handles.checkHandle('Robert`DROP TABLE STUDENTS;--');
const res = await ExtrinsicHelper.apiPromise.call.handlesRuntimeApi.checkHandle('Robert`DROP TABLE STUDENTS;--');
assert(!res.isEmpty, 'Expected a response');
assert.deepEqual(res.toHuman(), {
base_handle: 'Robert`DROP TABLE STUDENTS;--',
Expand All @@ -196,7 +196,7 @@ describe('🤝 Handles', function () {
});
});

it('expected outcome for a good handle with complex whitespace via Runtime API', async function () {
it('expected outcome for a good handle with complex whitespace', async function () {
const res = await ExtrinsicHelper.apiPromise.call.handlesRuntimeApi.checkHandle('नी हुन्‍न् ।');
assert(!res.isEmpty, 'Expected a response');
assert.deepEqual(res.toHuman(), {
Expand All @@ -207,22 +207,5 @@ describe('🤝 Handles', function () {
valid: true,
});
});

it('expected outcome for a good handle with complex whitespace via Custom API', async function () {
const res = await ExtrinsicHelper.apiPromise.rpc.handles.checkHandle('नी हुन्‍न् ।');
assert(!res.isEmpty, 'Expected a response');
assert.deepEqual(res.toHuman(), {
base_handle: 'नी हुन्‍न् ।',
canonical_base: 'नहनन।',
suffix_index: '0',
suffixes_available: true,
valid: true,
});

// Ensure these are the same canonically
const withoutWhitespace = await ExtrinsicHelper.apiPromise.rpc.handles.checkHandle('नी हुन्न् ।');
assert(!withoutWhitespace.isEmpty, 'Expected a response');
assert.equal(withoutWhitespace.toHuman().canonical_base, res.toHuman().canonical_base);
});
});
});
17 changes: 0 additions & 17 deletions js/api-augment/definitions/handles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,6 @@ export default {
],
type: 'bool',
},
checkHandle: {
description: 'Check the handle and return various data about it',
params: [
{
name: 'base_handle',
type: 'String',
},
],
type: 'CheckHandleResponse',
},
},
types: {
HandleSuffix: 'u16',
Expand All @@ -66,12 +56,5 @@ export default {
suffixes: 'Vec<HandleSuffix>',
base_handle: 'String',
},
CheckHandleResponse: {
base_handle: 'String',
canonical_base: 'String',
suffix_index: 'u16',
suffixes_available: 'bool',
valid: 'bool',
},
},
};
19 changes: 2 additions & 17 deletions pallets/handles/src/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
use common_helpers::rpc::map_rpc_result;
use common_primitives::{
handles::{
BaseHandle, CheckHandleResponse, DisplayHandle, HandleResponse,
PresumptiveSuffixesResponse, DEFAULT_SUFFIX_COUNT, MAX_SUFFIXES_COUNT,
BaseHandle, DisplayHandle, HandleResponse, PresumptiveSuffixesResponse,
DEFAULT_SUFFIX_COUNT, MAX_SUFFIXES_COUNT,
},
msa::MessageSourceId,
};
Expand Down Expand Up @@ -52,10 +52,6 @@ pub trait HandlesApi<BlockHash> {
/// validate a handle
#[method(name = "handles_validateHandle")]
fn validate_handle(&self, base_handle: String) -> RpcResult<bool>;

/// check a handle
#[method(name = "handles_checkHandle")]
fn check_handle(&self, base_handle: String) -> RpcResult<CheckHandleResponse>;
}

/// The client handler for the API used by Frequency Service RPC with `jsonrpsee`
Expand Down Expand Up @@ -137,15 +133,4 @@ where
let result = api.validate_handle(at, base_handle);
map_rpc_result(result)
}

fn check_handle(&self, base_handle: String) -> RpcResult<CheckHandleResponse> {
let api = self.client.runtime_api();
let at = self.client.info().best_hash;
let base_handle: BaseHandle = base_handle
.into_bytes()
.try_into()
.map_err(|_| HandlesRpcError::InvalidHandle)?;
let result = api.check_handle(at, base_handle);
map_rpc_result(result)
}
}
26 changes: 1 addition & 25 deletions pallets/handles/src/rpc/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::*;
use rpc_mock::*;

use common_primitives::{
handles::{BaseHandle, CheckHandleResponse, DisplayHandle, PresumptiveSuffixesResponse},
handles::{BaseHandle, DisplayHandle, PresumptiveSuffixesResponse},
node::Block,
};
use pallet_handles_runtime_api::HandlesRuntimeApi;
Expand Down Expand Up @@ -40,16 +40,6 @@ sp_api::mock_impl_runtime_apis! {
fn validate_handle(_base_handle: BaseHandle) -> bool {
true
}

fn check_handle(base_handle: BaseHandle) -> CheckHandleResponse {
CheckHandleResponse {
base_handle: base_handle.clone().into(),
valid: true,
suffix_index: 0,
suffixes_available: true,
canonical_base: "canonical_base".into()
}
}
}
}

Expand Down Expand Up @@ -104,17 +94,3 @@ async fn get_msa_for_handle_with_success() {
assert_eq!(true, result.is_ok());
assert_eq!(Some(VALID_MSA_ID), result.unwrap());
}

#[tokio::test]
async fn check_handle_with_success() {
let client = Arc::new(TestApi {});
let api = HandlesHandler::new(client);
let result = api.check_handle("base_handle".to_string());

assert_eq!(true, result.is_ok());
let response = result.unwrap();
assert!(response.valid);
assert!(response.suffixes_available);
assert_eq!(b"base_handle".to_vec(), response.base_handle);
assert_eq!(b"canonical_base".to_vec(), response.canonical_base);
}

0 comments on commit cc2b81b

Please sign in to comment.