Skip to content
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

Fixes for empty Name type and tests for UTF8 issue #43

Merged
merged 5 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/antelope/src/chain/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ pub fn n2s(value: u64) -> String {
}
i -= 1;
}
if i == 0 {
return String::from("");
}
String::from_utf8(s[0..i + 1].to_vec()).unwrap()
}

Expand Down
6 changes: 3 additions & 3 deletions crates/antelope/tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mod utils;
use utils::mock_provider::MockProvider;

use crate::utils::mock_provider;
use crate::utils::mock_provider::{make_mock_transaction, sign_mock_transaction};

#[tokio::test]
async fn chain_get_info() {
Expand Down Expand Up @@ -70,9 +71,8 @@ async fn chain_send_transaction() {
let client = APIClient::custom_provider(mock_provider).unwrap();
//let client = APIClient::default_provider(String::from("https://testnet.telos.caleos.io")).unwrap();
let info = client.v1_chain.get_info().await.unwrap();
let transaction =
mock_provider::make_mock_transaction(&info, Asset::from_string("0.0420 TLOS"));
let signed_transaction = mock_provider::sign_mock_transaction(&transaction, &info);
let transaction = make_mock_transaction(&info, Asset::from_string("0.0420 TLOS"));
let signed_transaction = sign_mock_transaction(&transaction, &info);
let result = client.v1_chain.send_transaction(signed_transaction).await;
assert!(result.is_ok(), "Transaction result should be ok");
let send_trx_response = result.unwrap();
Expand Down
10 changes: 4 additions & 6 deletions crates/antelope/tests/serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,10 @@ fn name() {
assert_eq!(name1, name2);
let name3 = Name::from_u64(6712742083569909760);
assert_eq!(name1, name3);
// TODO: The typescript lib produces empty string, are they the same? (. vs
// '')
assert_eq!(Name::from_u64(0).to_string(), ".");
/*
assert.equal(JSON.stringify(Name.from(UInt64.from(0))), """");
*/
assert_eq!(Name::from_u64(0).to_string(), "");
assert_eq!(name!(".me").to_string(), ".me");
assert_eq!(name!("you").to_string(), "you");
assert_eq!(name!("you.me").to_string(), "you.me");
}
/*

Expand Down
41 changes: 41 additions & 0 deletions crates/antelope/tests/ship.rs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions crates/antelope/tests/utils/mock_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ impl Provider for MockProvider {
}
}

#[allow(dead_code)]
pub fn make_mock_transaction(info: &GetInfoResponse, asset_to_transfer: Asset) -> Transaction {
let trx_header = info.get_transaction_header(90);

Expand Down Expand Up @@ -96,6 +97,7 @@ pub fn make_mock_transaction(info: &GetInfoResponse, asset_to_transfer: Asset) -
}
}

#[allow(dead_code)]
pub fn sign_mock_transaction(trx: &Transaction, info: &GetInfoResponse) -> SignedTransaction {
let private_key =
PrivateKey::from_str("5JW71y3njNNVf9fiGaufq8Up5XiGk68jZ5tYhKpy69yyU9cr7n9", false).unwrap();
Expand Down
1 change: 1 addition & 0 deletions crates/antelope/tests/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
//pub mod crypto;
//pub mod serializer;
pub mod mock_provider;
pub mod ship_types;
Loading
Loading