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

refactor: (dev_)deploy is now consistent across the board #56

Merged
merged 5 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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 examples/src/nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const NFT_WASM_FILEPATH: &str = "./examples/res/non_fungible_token.wasm";
async fn main() -> anyhow::Result<()> {
let worker = workspaces::sandbox();
let wasm = std::fs::read(NFT_WASM_FILEPATH)?;
let contract = worker.dev_deploy(wasm).await?;
let contract = worker.dev_deploy(&wasm).await?;

let outcome = contract
.call(&worker, "new_default_meta")
Expand Down
2 changes: 1 addition & 1 deletion examples/src/ref_finance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ async fn create_custom_ft(
worker: &Worker<impl DevNetwork>,
) -> anyhow::Result<Contract> {
let ft: Contract = worker
.dev_deploy(std::fs::read(FT_CONTRACT_FILEPATH)?)
.dev_deploy(&std::fs::read(FT_CONTRACT_FILEPATH)?)
.await?;

// Initialize our FT contract with owner metadata and total supply available
Expand Down
2 changes: 1 addition & 1 deletion examples/src/spooning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async fn deploy_status_contract(
msg: &str,
) -> anyhow::Result<Contract> {
let wasm = std::fs::read(STATUS_MSG_WASM_FILEPATH)?;
let contract = worker.dev_deploy(wasm).await?;
let contract = worker.dev_deploy(&wasm).await?;

// This will `call` into `set_status` with the message we want to set.
contract
Expand Down
2 changes: 1 addition & 1 deletion examples/src/status_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const STATUS_MSG_WASM_FILEPATH: &str = "./examples/res/status_message.wasm";
async fn main() -> anyhow::Result<()> {
let worker = workspaces::sandbox();
let wasm = std::fs::read(STATUS_MSG_WASM_FILEPATH)?;
let contract = worker.dev_deploy(wasm).await?;
let contract = worker.dev_deploy(&wasm).await?;

let outcome = contract
.call(&worker, "set_status")
Expand Down
1 change: 1 addition & 0 deletions workspaces/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ near-primitives = "0.5"
near-jsonrpc-primitives = "0.5"
near-jsonrpc-client = { version = "0.1", features = ["sandbox"] }
near-sandbox-utils = "0.1"
# near-sandbox-utils = { path = "../../../sandbox/crate" }
ChaoticTempest marked this conversation as resolved.
Show resolved Hide resolved

[build-dependencies]
near-sandbox-utils = "0.1"
Expand Down
4 changes: 2 additions & 2 deletions workspaces/src/network/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ impl Account {

/// Deploy contract code or WASM bytes to the account, and return us a new
/// [`Contract`] object that we can use to interact with the contract.
pub async fn deploy<T: Network, U: AsRef<[u8]>>(
pub async fn deploy<T: Network>(
&self,
worker: &Worker<T>,
wasm: U,
wasm: &[u8],
) -> anyhow::Result<CallExecution<Contract>> {
let outcome = worker
.client()
Expand Down
2 changes: 1 addition & 1 deletion workspaces/src/network/mainnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl TopLevelAccountCreator for Mainnet {
&self,
_id: AccountId,
_sk: SecretKey,
_wasm: Vec<u8>,
_wasm: &[u8],
) -> anyhow::Result<CallExecution<Contract>> {
panic!("Unsupported for now: https://github.com/near/workspaces-rs/issues/18");
}
Expand Down
6 changes: 3 additions & 3 deletions workspaces/src/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub trait TopLevelAccountCreator {
&self,
id: AccountId,
sk: SecretKey,
wasm: Vec<u8>,
wasm: &[u8],
) -> anyhow::Result<CallExecution<Contract>>;
}

Expand All @@ -57,7 +57,7 @@ pub trait AllowDevAccountCreation {}
pub trait DevAccountDeployer {
async fn dev_generate(&self) -> (AccountId, SecretKey);
async fn dev_create_account(&self) -> anyhow::Result<Account>;
async fn dev_deploy(&self, wasm: Vec<u8>) -> anyhow::Result<Contract>;
async fn dev_deploy(&self, wasm: &[u8]) -> anyhow::Result<Contract>;
}

#[async_trait]
Expand Down Expand Up @@ -87,7 +87,7 @@ where
account.into()
}

async fn dev_deploy(&self, wasm: Vec<u8>) -> anyhow::Result<Contract> {
async fn dev_deploy(&self, wasm: &[u8]) -> anyhow::Result<Contract> {
let (id, sk) = self.dev_generate().await;
let contract = self.create_tla_and_deploy(id.clone(), sk, wasm).await?;
contract.into()
Expand Down
10 changes: 8 additions & 2 deletions workspaces/src/network/sandbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,18 @@ impl TopLevelAccountCreator for Sandbox {
&self,
id: AccountId,
sk: SecretKey,
wasm: Vec<u8>,
wasm: &[u8],
) -> anyhow::Result<CallExecution<Contract>> {
let root_signer = self.root_signer();
let outcome = self
.client
.create_account_and_deploy(&root_signer, &id, sk.public_key(), DEFAULT_DEPOSIT, wasm)
.create_account_and_deploy(
&root_signer,
&id,
sk.public_key(),
DEFAULT_DEPOSIT,
wasm.into(),
)
.await?;

let signer = InMemorySigner::from_secret_key(id.clone(), sk);
Expand Down
5 changes: 3 additions & 2 deletions workspaces/src/network/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,13 @@ impl TopLevelAccountCreator for Testnet {
&self,
id: AccountId,
sk: SecretKey,
wasm: Vec<u8>,
wasm: &[u8],
) -> anyhow::Result<CallExecution<Contract>> {
let signer = InMemorySigner::from_secret_key(id.clone(), sk.clone());
let account = self.create_tla(id.clone(), sk).await?;
let account = account.into_result()?;
let outcome = self.client.deploy(&signer, &id, wasm).await?;

let outcome = self.client.deploy(&signer, &id, wasm.into()).await?;

Ok(CallExecution {
result: Contract::account(account),
Expand Down
2 changes: 1 addition & 1 deletion workspaces/src/worker/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ where
&self,
id: AccountId,
sk: SecretKey,
wasm: Vec<u8>,
wasm: &[u8],
) -> anyhow::Result<CallExecution<Contract>> {
self.workspace.create_tla_and_deploy(id, sk, wasm).await
}
Expand Down
2 changes: 1 addition & 1 deletion workspaces/tests/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn expected() -> NftMetadata {
async fn test_dev_deploy() -> anyhow::Result<()> {
let worker = workspaces::sandbox();
let wasm = std::fs::read(NFT_WASM_FILEPATH)?;
let contract = worker.dev_deploy(wasm).await?;
let contract = worker.dev_deploy(&wasm).await?;

let _result = contract
.call(&worker, "new_default_meta")
Expand Down
2 changes: 1 addition & 1 deletion workspaces/tests/patch_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async fn view_status_state(
worker: Worker<impl DevNetwork>,
) -> anyhow::Result<(AccountId, StatusMessage)> {
let wasm = std::fs::read(STATUS_MSG_WASM_FILEPATH)?;
let contract = worker.dev_deploy(wasm).await.unwrap();
let contract = worker.dev_deploy(&wasm).await.unwrap();

contract
.call(&worker, "set_status")
Expand Down