-
Notifications
You must be signed in to change notification settings - Fork 11
fix: Change hash encoding, support passing in code without borsh
#152
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ use common::utils::{ | |
| }; | ||
| use near_plugins::upgradable::FunctionCallArgs; | ||
| use near_sdk::serde_json::json; | ||
| use near_sdk::{CryptoHash, Duration, Gas, NearToken, Timestamp}; | ||
| use near_sdk::{Duration, Gas, NearToken, Timestamp}; | ||
| use near_workspaces::network::Sandbox; | ||
| use near_workspaces::result::ExecutionFinalResult; | ||
| use near_workspaces::{Account, AccountId, Contract, Worker}; | ||
|
|
@@ -203,19 +203,17 @@ impl Setup { | |
| } | ||
| } | ||
|
|
||
| /// Panics if the conversion fails. | ||
| fn convert_code_to_crypto_hash(code: &[u8]) -> CryptoHash { | ||
| near_sdk::env::sha256(code) | ||
| .try_into() | ||
| .expect("Code should be converted to CryptoHash") | ||
| /// Converts code to a base58-encoded CryptoHash string. | ||
| fn convert_code_to_crypto_hash(code: &[u8]) -> String { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not crypto_hash; right now, we are returning CryptoHash. It's not very important, but maybe we could rename it to convert_code_to_bs58_encoded_hash or something like that?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @r-near |
||
| let hash = near_sdk::env::sha256(code); | ||
| near_sdk::bs58::encode(hash).into_string() | ||
| } | ||
|
|
||
| /// Computes the hash `code` according the to requirements of the `hash` parameter of | ||
| /// `Upgradable::up_deploy_code`. | ||
| fn convert_code_to_deploy_hash(code: &[u8]) -> String { | ||
| use near_sdk::base64::Engine; | ||
| let hash = near_sdk::env::sha256(code); | ||
| near_sdk::base64::prelude::BASE64_STANDARD.encode(hash) | ||
| near_sdk::bs58::encode(hash).into_string() | ||
| } | ||
|
|
||
| /// Smoke test of contract setup. | ||
|
|
@@ -722,7 +720,7 @@ async fn test_deploy_code_in_batch_transaction_pitfall() -> anyhow::Result<()> { | |
| } })) | ||
| .gas(Gas::from_tgas(220)); | ||
| let fn_call_remove_code = near_workspaces::operations::Function::new("up_stage_code") | ||
| .args_borsh(Vec::<u8>::new()) | ||
| .args(Vec::<u8>::new()) | ||
| .gas(Gas::from_tgas(80)); | ||
|
|
||
| let res = dao | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.