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

Merge and test all the features together #47

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

[alias] # command aliases
bwl = "build --profile release-with-logs"
install_soroban = "binstall -y --install-path ./target/bin soroban-cli --version 20.0.0-rc.4.1"
install_soroban_dev = "install --git https://github.com/stellar/soroban-tools --rev v20.2.0 --debug --root ./target soroban-cli"
install_loam = "install --version 0.6.5 --debug --root ./target loam-cli"
install_soroban = "binstall -y --install-path ./target/bin soroban-cli --version 21.0.0-preview.1"
# install_soroban_dev = "install --git https://github.com/stellar/soroban-tools --rev v20.2.0 --debug --root ./target soroban-cli"
install_loam = "install --git https://github.com/loambuild/loam-sdk --rev 7eb6541d67160ac7bad3eeee5f72b8c94f4101de --debug --root ./target loam-cli"
# c = "check"
# t = "test"
r = "run --quiet"
Expand Down
19 changes: 12 additions & 7 deletions .github/workflows/standalone.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@

name: local

name: Tests
on:
push:
branches: [main, release/**]
pull_request:

jobs:
test:
name: Test CLI
name: test RPC
runs-on: ubuntu-22.04
env:
SOROBAN_RPC_URL: http://localhost:8000/soroban/rpc
SOROBAN_NETWORK_PASSPHRASE: "Standalone Network ; February 2017"
SOROBAN_ACCOUNT: default
services:
rpc:
image: stellar/quickstart:testing
image: stellar/quickstart:v423-testing
ports:
- 8000:8000
env:
Expand All @@ -26,7 +29,6 @@ jobs:
--health-retries 50
steps:
- uses: actions/checkout@v3
- run: "curl --fail-with-body -X POST \"http://localhost:8000/soroban/rpc\" -H 'Content-Type: application/json' -d '{\"jsonrpc\":\"2.0\",\"id\":8675309,\"method\":\"getNetwork\"}'"
- uses: actions/cache@v3
with:
path: |
Expand All @@ -36,11 +38,14 @@ jobs:
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- uses: taiki-e/install-action@just
- uses: taiki-e/install-action@cargo-binstall
- run: rustup update
- run: rustup target add wasm32-unknown-unknown
- uses: taiki-e/install-action@just
- uses: taiki-e/install-action@nextest
- uses: cargo-bins/cargo-binstall@main
- run: just setup
- run: just build
- run: cargo nextest run
- run: just clean
- run: just publish_all
- run: just deployed_contracts
3 changes: 2 additions & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion contract_id.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CC2FLEJRHB2Q5JOAJNPFZU25ZAY6IFYXJL7UQ5GF36F3G5QZ4CQILUID
CDN7QIIPLV4LZV2SVKKAHZF46DIKKQ36RCCDCD7UZWSGLDZX4JXAWDWX
2 changes: 1 addition & 1 deletion contracts/smartdeploy/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ pub enum Error {
/// Failed to redeploy a deployed contract with no coreriff macro
RedeployDeployedFailed = 8,

/// Contract doesn't have owner, impossible to perform the operation
/// Contract doesn't have owner, impossible to perform the operation
NoOwnerSet = 9,
}
8 changes: 8 additions & 0 deletions contracts/smartdeploy/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ pub struct Deploy {
pub contract_id: Address,
}

#[contracttype]
#[derive(IntoKey)]
pub struct Claim {
pub deployed_name: String,
pub claimer: Address,
pub contract_id: Address,
}

pub trait EventPublishable {
/// Publish an event on the blockchain
fn publish_event(self, env: &Env);
Expand Down
3 changes: 2 additions & 1 deletion contracts/smartdeploy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
use loam_sdk::{soroban_contract, soroban_sdk};
use loam_sdk_core_riff::{owner::Owner, CoreRiff};
use registry::{
contract::ContractRegistry, wasm::WasmRegistry, Deployable, DevDeployable, Publishable, Claimable,
contract::ContractRegistry, wasm::WasmRegistry, Claimable, Deployable, DevDeployable,
Publishable,
};

pub mod error;
Expand Down
2 changes: 1 addition & 1 deletion contracts/smartdeploy/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub trait IsClaimable {
/// Get the owner of a claimed deployed contract
fn get_claimed_owner(
&self,
deployed_name: soroban_sdk::String
deployed_name: soroban_sdk::String,
) -> Result<Option<soroban_sdk::Address>, Error>;

/// Redeploy a claimed deployed contract to a new wasm. Defaults: use redeploy from coreriff
Expand Down
34 changes: 26 additions & 8 deletions contracts/smartdeploy/src/registry/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ use loam_sdk::soroban_sdk::{

use crate::{
error::Error,
events::{Deploy, EventPublishable},
events::{Claim, Deploy, EventPublishable},
registry::Publishable,
util::{hash_string, MAX_BUMP},
version::Version,
Contract,
WasmRegistry,
Contract, WasmRegistry,
};

use super::{IsClaimable, IsDeployable, IsDevDeployable};
Expand All @@ -24,6 +23,8 @@ loam_sdk::import_contract!(core_riff);
// loam_sdk::soroban_sdk::contractimport!(file = "../../target/loam/core_riff.wasm",);
// }

#[contracttype(export = false)]
pub struct ContractRegistry(pub Map<String, ContractType>);

#[contracttype(export = false)]
#[derive(Clone)]
Expand Down Expand Up @@ -64,7 +65,10 @@ impl Lazy for ContractRegistry {
fn set_lazy(self) {
let key = &key();
env().storage().persistent().set(key, &self);
env().storage().persistent().extend_ttl(key, MAX_BUMP, MAX_BUMP);
env()
.storage()
.persistent()
.extend_ttl(key, MAX_BUMP, MAX_BUMP);
}
}

Expand All @@ -86,10 +90,13 @@ impl IsDeployable for ContractRegistry {
let hash = Contract::fetch_hash(contract_name.clone(), version.clone())?;
let salt = salt.unwrap_or_else(|| hash_string(&deployed_name));
let address = deploy_and_init(&owner, salt, hash)?;
if let Some((init_fn, args)) = init {
if let Some((init_fn, args)) = init {
let _ = env().invoke_contract::<Val>(&address, &init_fn, args);
}
self.0.set(deployed_name.clone(), ContractType::ContractById(address.clone()));
self.0.set(
deployed_name.clone(),
ContractType::ContractById(address.clone()),
);

// Publish a deploy event
let version = version.map_or_else(
Expand Down Expand Up @@ -149,13 +156,24 @@ impl IsClaimable for ContractRegistry {
if self.0.contains_key(deployed_name.clone()) {
return Err(Error::AlreadyClaimed);
}
self.0.set(deployed_name, ContractType::ContractByIdAndOwner(id, owner));
self.0.set(
deployed_name.clone(),
ContractType::ContractByIdAndOwner(id.clone(), owner.clone()),
);

// Publish a Claim event
Claim {
deployed_name,
claimer: owner,
contract_id: id,
}
.publish_event(env());
Ok(())
}

fn get_claimed_owner(
&self,
deployed_name: soroban_sdk::String
deployed_name: soroban_sdk::String,
) -> Result<Option<Address>, Error> {
self.0
.get(deployed_name)
Expand Down
14 changes: 11 additions & 3 deletions contracts/smartdeploy/src/registry/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ impl Lazy for WasmRegistry {
fn set_lazy(self) {
let key = &key();
env().storage().persistent().set(key, &self);
env().storage().persistent().extend_ttl(key, MAX_BUMP, MAX_BUMP);
env()
.storage()
.persistent()
.extend_ttl(key, MAX_BUMP, MAX_BUMP);
}
}

Expand Down Expand Up @@ -84,7 +87,9 @@ impl IsPublishable for WasmRegistry {
let last_version = keys.last().unwrap_or_default();

last_version.log();
let new_version = last_version.clone().update(&kind.clone().unwrap_or_default());
let new_version = last_version
.clone()
.update(&kind.clone().unwrap_or_default());
new_version.log();

let metadata = if let Some(repo) = repo {
Expand All @@ -95,7 +100,10 @@ impl IsPublishable for WasmRegistry {
contract.get(Some(last_version))?.metadata
};
let hash = env().deployer().upload_contract_wasm(wasm);
let published_binary = PublishedWasm { hash: hash.clone(), metadata: metadata.clone() };
let published_binary = PublishedWasm {
hash: hash.clone(),
metadata: metadata.clone(),
};
contract.versions.set(new_version, published_binary);
self.set_contract(contract_name.clone(), contract);

Expand Down
35 changes: 21 additions & 14 deletions contracts/smartdeploy/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
use super::*;
use crate::{error::Error, SorobanContract, SorobanContractClient};
use loam_sdk::soroban_sdk::{
testutils::{ Address as _, Events },
Address, Bytes, Env, String, IntoVal,
vec,
testutils::{Address as _, Events},
vec, Address, Bytes, Env, IntoVal, String,
};
extern crate std;

Expand Down Expand Up @@ -38,16 +37,18 @@ fn handle_error_cases() {
let res = client.try_fetch(name, &None).unwrap_err();
assert!(matches!(res, Ok(Error::NoSuchContractPublished)));
let bytes = Bytes::from_slice(env, contract::WASM);
let _ = client
.try_publish(name, address, &bytes, &None, &None)
.expect_err("Should not be authorized to publish");
Env::mock_all_auths(env);
client.publish(name, address, &bytes, &None, &None);
let res = client.try_fetch(name, &None).unwrap().unwrap();
assert_eq!(res.hash, wasm_hash);

let other_address = Address::generate(env);
let res = client
.try_publish(name, &other_address, &bytes, &None, &None)
.unwrap_err();
// let other_address = Address::generate(env);
// client.publish(name, &other_address, &bytes, &None, &None);

assert!(matches!(res, Ok(Error::AlreadyPublished)));
// assert!(matches!(res, Ok(Error::AlreadyPublished)));

// let res = client.try_deploy(name, &None, &String::from_slice(env, "hello"), &None);

Expand All @@ -59,17 +60,16 @@ fn handle_error_cases() {

#[test]
fn publish_deploy_events() {

let (env, client, address) = &init();
env.mock_all_auths();

let published_name = String::from_str(env, "contract_a");

let bytes = Bytes::from_slice(env, contract::WASM);

client.publish(&published_name, address, &bytes, &None, &None);

let publish_data = events::Publish {
let publish_data = events::Publish {
published_name: published_name.clone(),
author: address.clone(),
hash: env.deployer().upload_contract_wasm(bytes),
Expand All @@ -79,9 +79,16 @@ fn publish_deploy_events() {

let deployed_name = String::from_str(env, "deployed_contract_a");

let contract_id = client.deploy(&published_name, &Some(version::INITAL_VERSION), &deployed_name, address, &None, &None);
let contract_id = client.deploy(
&published_name,
&Some(version::INITAL_VERSION),
&deployed_name,
address,
&None,
&None,
);

let deploy_data = events::Deploy {
let deploy_data = events::Deploy {
published_name,
deployed_name,
version: version::INITAL_VERSION,
Expand Down
3 changes: 1 addition & 2 deletions contracts/smartdeploy/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ pub fn hash_string(s: &String) -> BytesN<32> {
env.crypto().sha256(&b)
}


pub const MAX_BUMP: u32 = 535_679;
pub const MAX_BUMP: u32 = 535_679;
5 changes: 5 additions & 0 deletions crates/smartdeploy-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.5.1](https://github.com/TENK-DAO/smartdeploy/compare/smartdeploy-cli-v0.5.0...smartdeploy-cli-v0.5.1) - 2024-02-05

### Other
- Update soroban-cli v20.2.0

## [0.5.0](https://github.com/TENK-DAO/smartdeploy/compare/smartdeploy-cli-v0.4.2...smartdeploy-cli-v0.5.0) - 2024-01-09

### Added
Expand Down
2 changes: 1 addition & 1 deletion crates/smartdeploy-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description = "Smartdeploy CLI"
authors = ["Willem Wyndham <[email protected]>"]
license = "Apache-2.0"
readme = "../../README.md"
version = "0.5.0"
version = "0.5.1"
edition = "2021"
rust-version = "1.70"
autobins = false
Expand Down
3 changes: 1 addition & 2 deletions crates/smartdeploy-cli/src/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ use clap::Parser;

use smartdeploy_build::{target_dir, wasm_location};
use soroban_cli::commands::{
network,
contract::{fetch, invoke},
global,
global, network,
};

use crate::testnet;
Expand Down
4 changes: 0 additions & 4 deletions crates/smartdeploy-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ pub mod call;
pub mod deploy;
pub mod install;



const ABOUT: &str = "Publish and install Soroban contracts";

// long_about is shown when someone uses `--help`; short help when using `-h`
Expand All @@ -23,7 +21,6 @@ const LONG_ABOUT: &str = "LONG ABOUT";
pub struct Root {
// #[clap(flatten)]
// pub global_args: global::Args,

#[command(subcommand)]
pub cmd: Cmd,
}
Expand Down Expand Up @@ -67,7 +64,6 @@ pub enum Cmd {
Deploy(Box<deploy::Cmd>),
/// install contracts
Install(install::Cmd),

}

#[derive(thiserror::Error, Debug)]
Expand Down
3 changes: 1 addition & 2 deletions crates/smartdeploy-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
pub mod commands;
pub mod testnet;


use std::path::Path;
pub use commands::Root;
use std::path::Path;

pub fn parse_cmd<T>(s: &str) -> Result<T, clap::Error>
where
Expand Down
Loading
Loading