-
Notifications
You must be signed in to change notification settings - Fork 124
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
Add subscription ID recognition to tungstenite and ws-rpc client #662
Merged
Merged
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
154e49b
fix error
haerdib f470b0a
fix clippy warning
haerdib da11078
seems to wrok
haerdib fa54d27
check for subscirption id
haerdib 66b36d3
fix clippy
haerdib b110bef
fix typo
haerdib 71ce17d
remove error logs
haerdib 524b196
add info log
haerdib 8770206
we expect an immediate response
haerdib e3c5206
add tests for rpc client
haerdib b9f1c38
fix test and clean up ws_rpc client
haerdib bb5ee28
fix test
haerdib e03ef62
fix test
haerdib 6460173
fix clippy
haerdib 994e57a
fix tests
haerdib b8aea24
git commit
haerdib 867845d
add missing comma
haerdib 3ec0c30
extract helper functions
haerdib 98df866
add missing helper file
haerdib 4243aee
remove code from ws-client and use helpers
haerdib 86dfc27
fix compile errors
haerdib 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
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
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
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
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,62 @@ | ||
/* | ||
Copyright 2019 Supercomputing Systems AG | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
use sp_core::{ | ||
crypto::{Pair, Ss58Codec}, | ||
sr25519, | ||
}; | ||
use sp_runtime::MultiAddress; | ||
use substrate_api_client::{ | ||
ac_primitives::{AssetRuntimeConfig, ExtrinsicSigner}, | ||
extrinsic::BalancesExtrinsics, | ||
rpc::TungsteniteRpcClient, | ||
Api, GetAccountInformation, SubmitAndWatch, XtStatus, | ||
}; | ||
|
||
fn main() { | ||
// Setup | ||
let alice: sr25519::Pair = Pair::from_string( | ||
"0xe5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a", | ||
None, | ||
) | ||
.unwrap(); | ||
let client = TungsteniteRpcClient::with_default_url(100); | ||
let mut api = Api::<AssetRuntimeConfig, _>::new(client).unwrap(); | ||
api.set_signer(ExtrinsicSigner::<AssetRuntimeConfig>::new(alice.clone())); | ||
|
||
let bob = sr25519::Public::from_ss58check("5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty") | ||
.unwrap(); | ||
let bob_balance = api.get_account_data(&bob.into()).unwrap().unwrap_or_default().free; | ||
|
||
// Check for failed extrinsic failed onchain | ||
let xt = api.balance_transfer_allow_death(MultiAddress::Id(bob.into()), bob_balance + 1); | ||
let result = api.submit_and_watch_extrinsic_until(xt.clone(), XtStatus::InBlock); | ||
assert!(format!("{:?}", result).contains("FundsUnavailable")); | ||
|
||
// Check directly failed extrinsic (before actually submitted to a block) | ||
let result = api.submit_and_watch_extrinsic_until(xt, XtStatus::InBlock); | ||
assert!(result.is_err()); | ||
assert!(format!("{:?}", result).contains("ExtrinsicFailed")); | ||
|
||
// Check for successful extrinisc | ||
let xt = api.balance_transfer_allow_death(MultiAddress::Id(bob.into()), bob_balance / 2); | ||
let _block_hash = api | ||
.submit_and_watch_extrinsic_until(xt, XtStatus::InBlock) | ||
.unwrap() | ||
.block_hash | ||
.unwrap(); | ||
let bob_new_balance = api.get_account_data(&bob.into()).unwrap().unwrap().free; | ||
assert!(bob_new_balance > bob_balance); | ||
} |
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.
As far as I understand, all the following logic is analyzing a string. I would put this logic into its own function and write a test for each flow through. Then you know, that it's doing what you expect.
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.
I agree, unit testing does make sense here. But not just here, but also in the ws_client and other functions of this client. Would you agree to do that in a separate issue and PR?
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.
I would add tests for new logic from this PR in this PR. For adding tests to existing code, I would create a new issue.
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.
Added issue: #663, commit adding unit tests for changed code is incoming.