Skip to content

Commit

Permalink
Merge pull request #165 from kommitters/v0.14
Browse files Browse the repository at this point in the history
Release v0.14.0
  • Loading branch information
juanmagiraldor authored Dec 21, 2023
2 parents 7c7252f + d28e227 commit b7a6637
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- uses: actions/checkout@v3
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
- run: rustup target add wasm32-unknown-unknown
- run: cargo install --locked --version 20.0.0-rc2 soroban-cli
- run: cargo install --locked --version 20.1.0 soroban-cli
- name: Build contracts
run: |
soroban contract build
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.14.0 (21.12.2023)
- [Bump `soroban-sdk` to `20.0.0`](https://github.com/kommitters/chaincerts-smart-contracts/issues/160)
- [Extend Instance TTL on initialization to 31 days in ledgers](https://github.com/kommitters/chaincerts-smart-contracts/pull/163)

## 0.13.0 (07.12.2023)

- [Contracts improvements](https://github.com/kommitters/chaincerts-smart-contracts/pull/155)
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ resolver = "2"
members = ["deployer_contract", "vault_contract", "vc_issuance_contract"]

[workspace.package]
version = "0.13.0"
version = "0.14.0"
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/kommitters/chaincerts-smart-contracts"

[workspace.dependencies]
soroban-sdk = { version = "=20.0.0-rc2.2" }
soroban-sdk = { version = "=20.0.0" }

[profile.release]
opt-level = "z"
Expand Down
Binary file modified deployer_contract/did_contract.wasm
100755 → 100644
Binary file not shown.
62 changes: 28 additions & 34 deletions deployer_contract/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,32 @@ fn test_from_contract() {

// Deploy contract using deployer, and include an init function to call.
let salt = BytesN::from_array(&env, &[0; 32]);
let address = Address::random(&env);
let address = Address::generate(&env);
let init_args = did_init_args(&env, &address);
let (contract_id, init_result) = client.deploy(&client.address, &wasm_id, &salt, &init_args);
assert!(init_result.is_void());

let expected_did_document = DIDDocument {
id: String::from_slice(&env, "did:chaincerts:ABC123"),
authentication: vec![
&env,
String::from_slice(&env, "did:chaincerts:ABC123#key-1"),
],
id: String::from_str(&env, "did:chaincerts:ABC123"),
authentication: vec![&env, String::from_str(&env, "did:chaincerts:ABC123#key-1")],
context: vec![
&env,
String::from_slice(&env, "https://www.w3.org/ns/did/v1"),
String::from_slice(&env, "https://www.example.com/context/v1"),
String::from_str(&env, "https://www.w3.org/ns/did/v1"),
String::from_str(&env, "https://www.example.com/context/v1"),
],
services: vec![
&env,
Service {
type_: String::from_slice(&env, "VerifiableCredential"),
service_endpoint: String::from_slice(&env, "https://did.chaincerts.co/ABC123"),
type_: String::from_str(&env, "VerifiableCredential"),
service_endpoint: String::from_str(&env, "https://did.chaincerts.co/ABC123"),
},
],
verification_method: vec![
&env,
VerificationMethod {
id: String::from_slice(&env, "did:chaincerts:ABC123#key-1"),
type_: String::from_slice(&env, "Ed25519VerificationKey2020"),
controller: String::from_slice(&env, "did:chaincerts:ABC123"),
id: String::from_str(&env, "did:chaincerts:ABC123#key-1"),
type_: String::from_str(&env, "Ed25519VerificationKey2020"),
controller: String::from_str(&env, "did:chaincerts:ABC123"),
blockchain_account_id: address,
},
],
Expand All @@ -76,11 +73,11 @@ fn test_deploy_from_address() {
let wasm_hash = env.deployer().upload_contract_wasm(contract::WASM);

// Define a deployer address that needs to authorize the deployment.
let deployer = Address::random(&env);
let deployer = Address::generate(&env);

// Deploy contract using deployer, and include an init function to call.
let salt = BytesN::from_array(&env, &[0; 32]);
let address = Address::random(&env);
let address = Address::generate(&env);
let init_fn_args = did_init_args(&env, &address);
env.mock_all_auths();
let (contract_id, init_result) =
Expand All @@ -89,29 +86,26 @@ fn test_deploy_from_address() {
assert!(init_result.is_void());

let expected_did_document = DIDDocument {
id: String::from_slice(&env, "did:chaincerts:ABC123"),
authentication: vec![
&env,
String::from_slice(&env, "did:chaincerts:ABC123#key-1"),
],
id: String::from_str(&env, "did:chaincerts:ABC123"),
authentication: vec![&env, String::from_str(&env, "did:chaincerts:ABC123#key-1")],
context: vec![
&env,
String::from_slice(&env, "https://www.w3.org/ns/did/v1"),
String::from_slice(&env, "https://www.example.com/context/v1"),
String::from_str(&env, "https://www.w3.org/ns/did/v1"),
String::from_str(&env, "https://www.example.com/context/v1"),
],
services: vec![
&env,
Service {
type_: String::from_slice(&env, "VerifiableCredential"),
service_endpoint: String::from_slice(&env, "https://did.chaincerts.co/ABC123"),
type_: String::from_str(&env, "VerifiableCredential"),
service_endpoint: String::from_str(&env, "https://did.chaincerts.co/ABC123"),
},
],
verification_method: vec![
&env,
VerificationMethod {
id: String::from_slice(&env, "did:chaincerts:ABC123#key-1"),
type_: String::from_slice(&env, "Ed25519VerificationKey2020"),
controller: String::from_slice(&env, "did:chaincerts:ABC123"),
id: String::from_str(&env, "did:chaincerts:ABC123#key-1"),
type_: String::from_str(&env, "Ed25519VerificationKey2020"),
controller: String::from_str(&env, "did:chaincerts:ABC123"),
blockchain_account_id: address,
},
],
Expand All @@ -124,26 +118,26 @@ fn test_deploy_from_address() {
}

fn did_init_args(env: &Env, address: &Address) -> Vec<Val> {
let id = String::from_slice(env, "did:chaincerts:ABC123");
let id = String::from_str(env, "did:chaincerts:ABC123");
let authentication_params = (
String::from_slice(env, "did:chaincerts:ABC123#key-1"),
String::from_str(env, "did:chaincerts:ABC123#key-1"),
address,
);
let context = vec![
env,
String::from_slice(env, "https://www.w3.org/ns/did/v1"),
String::from_slice(env, "https://www.example.com/context/v1"),
String::from_str(env, "https://www.w3.org/ns/did/v1"),
String::from_str(env, "https://www.example.com/context/v1"),
];
let method = Method {
type_: String::from_slice(env, "otp"),
type_: String::from_str(env, "otp"),
verified: true,
timestamp: 1684872059,
service: OptionMethodService::None,
};
let verification_processes = vec![env, method];
let service = Service {
type_: String::from_slice(env, "VerifiableCredential"),
service_endpoint: String::from_slice(env, "https://did.chaincerts.co/ABC123"),
type_: String::from_str(env, "VerifiableCredential"),
service_endpoint: String::from_str(env, "https://did.chaincerts.co/ABC123"),
};
let services = vec![env, service];
let public_add_cap: Option<CapabilityInvocation> = Option::None;
Expand Down
2 changes: 1 addition & 1 deletion did_contract
8 changes: 5 additions & 3 deletions vault_contract/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ use soroban_sdk::{
contract, contractimpl, contractmeta, panic_with_error, Address, Env, IntoVal, Map, String, Vec,
};

const LEDGERS_THRESHOLD: u32 = 1;
const LEDGERS_TO_EXTEND: u32 = 535_000;
// MAXIMUM ENTRY TTL:
// 31 days, 12 ledger close per minute.
// (12 * 60 * 24 * 31) - 1
const LEDGERS_TO_EXTEND: u32 = 535_679;

contractmeta!(
key = "Description",
Expand All @@ -33,7 +35,7 @@ impl VaultTrait for VaultContract {

e.storage()
.instance()
.bump(LEDGERS_THRESHOLD, LEDGERS_TO_EXTEND);
.extend_ttl(LEDGERS_TO_EXTEND, LEDGERS_TO_EXTEND);
}

fn authorize_issuer(e: Env, admin: Address, issuer: Address, did: String) {
Expand Down
32 changes: 16 additions & 16 deletions vault_contract/src/test/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn test_authorize_issuer_with_invalid_admin() {
contract,
} = VaultContractTest::setup();

let invalid_admin = Address::random(&env);
let invalid_admin = Address::generate(&env);
contract.initialize(&admin, &dids);

contract.authorize_issuer(&invalid_admin, &issuer, &did);
Expand All @@ -93,7 +93,7 @@ fn test_authorize_issuer_with_not_registered_vault() {
contract,
} = VaultContractTest::setup();
contract.initialize(&admin, &dids);
let invalid_did = String::from_slice(&env, "did:chaincerts:3mtjfbxad3wzh7qa4w5f7q4h");
let invalid_did = String::from_str(&env, "did:chaincerts:3mtjfbxad3wzh7qa4w5f7q4h");

contract.authorize_issuer(&admin, &issuer, &invalid_did);
}
Expand Down Expand Up @@ -146,7 +146,7 @@ fn test_revoke_issuer_with_invalid_admin() {
contract.initialize(&admin, &dids);
contract.authorize_issuer(&admin, &issuer, &did);

let invalid_admin = Address::random(&env);
let invalid_admin = Address::generate(&env);
contract.revoke_issuer(&invalid_admin, &issuer, &did);
}

Expand All @@ -165,7 +165,7 @@ fn test_revoke_issuer_when_issuer_is_not_found() {
contract.initialize(&admin, &dids);
contract.authorize_issuer(&admin, &issuer, &did);

let invalid_issuer = Address::random(&env);
let invalid_issuer = Address::generate(&env);
contract.revoke_issuer(&admin, &invalid_issuer, &did);
}

Expand All @@ -181,7 +181,7 @@ fn test_revoke_issuer_with_not_registered_did() {
contract,
} = VaultContractTest::setup();
contract.initialize(&admin, &dids);
let invalid_did = String::from_slice(&env, "did:chaincerts:3mtjfbxad3wzh7qa4w5f7q4h");
let invalid_did = String::from_str(&env, "did:chaincerts:3mtjfbxad3wzh7qa4w5f7q4h");

contract.revoke_issuer(&admin, &issuer, &invalid_did);
}
Expand Down Expand Up @@ -259,7 +259,7 @@ fn test_store_vc_with_issuer_not_found() {
contract,
} = VaultContractTest::setup();

let invalid_issuer = Address::random(&env);
let invalid_issuer = Address::generate(&env);

let VCVaultContractTest {
vc_id,
Expand Down Expand Up @@ -314,7 +314,7 @@ fn test_store_vc_with_vault_not_found() {
issuer,
contract,
} = VaultContractTest::setup();
let invalid_did = String::from_slice(&env, "did:chaincerts:3mtjfbxad3wzh7qa4w5f7q4h");
let invalid_did = String::from_str(&env, "did:chaincerts:3mtjfbxad3wzh7qa4w5f7q4h");

let VCVaultContractTest {
vc_id,
Expand Down Expand Up @@ -348,7 +348,7 @@ fn test_get_vault_not_found() {

contract.initialize(&admin, &dids);

let bad_vault_did: String = String::from_slice(&env, "did:chaincerts:xyz123");
let bad_vault_did: String = String::from_str(&env, "did:chaincerts:xyz123");
contract.get_vault(&bad_vault_did);
}

Expand Down Expand Up @@ -384,9 +384,9 @@ fn test_list_vaults() {
issuance_contract_address,
} = get_vc_setup(&env);

let vc_id2 = String::from_slice(&env, "vc_id2");
let vc_id3 = String::from_slice(&env, "vc_id3");
let did2 = String::from_slice(&env, "did:chaincerts:3mtjfbxad3wzh7qa4w5f7q4h");
let vc_id2 = String::from_str(&env, "vc_id2");
let vc_id3 = String::from_str(&env, "vc_id3");
let did2 = String::from_str(&env, "did:chaincerts:3mtjfbxad3wzh7qa4w5f7q4h");
let dids = vec![&env, did.clone(), did2.clone()];

contract.initialize(&admin, &dids);
Expand Down Expand Up @@ -427,7 +427,7 @@ fn test_register_vault() {
issuer: _,
contract,
} = VaultContractTest::setup();
let did2 = String::from_slice(&env, "did:chaincerts:3mtjfbxad3wzh7qa4w5f7q4h");
let did2 = String::from_str(&env, "did:chaincerts:3mtjfbxad3wzh7qa4w5f7q4h");

contract.initialize(&admin, &dids);
contract.register_vault(&admin, &did2);
Expand Down Expand Up @@ -460,8 +460,8 @@ fn test_register_vault_with_invalid_admin() {
issuer: _,
contract,
} = VaultContractTest::setup();
let did2 = String::from_slice(&env, "did:chaincerts:3mtjfbxad3wzh7qa4w5f7q4h");
let invalid_admin = Address::random(&env);
let did2 = String::from_str(&env, "did:chaincerts:3mtjfbxad3wzh7qa4w5f7q4h");
let invalid_admin = Address::generate(&env);

contract.initialize(&admin, &dids);
contract.register_vault(&invalid_admin, &did2);
Expand Down Expand Up @@ -493,7 +493,7 @@ fn test_revoke_vault_with_invalid_admin() {
issuer: _,
contract,
} = VaultContractTest::setup();
let invalid_admin = Address::random(&env);
let invalid_admin = Address::generate(&env);

contract.initialize(&admin, &dids);
contract.revoke_vault(&invalid_admin, &did);
Expand All @@ -510,7 +510,7 @@ fn test_revoke_vault_with_no_registered_did() {
issuer: _,
contract,
} = VaultContractTest::setup();
let invalid_did = String::from_slice(&env, "did:chaincerts:3mtjfbxad3wzh7qa4w5f7q4h");
let invalid_did = String::from_str(&env, "did:chaincerts:3mtjfbxad3wzh7qa4w5f7q4h");

contract.initialize(&admin, &dids);
contract.revoke_vault(&admin, &invalid_did);
Expand Down
12 changes: 6 additions & 6 deletions vault_contract/src/test/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ impl<'a> VaultContractTest<'a> {
pub fn setup() -> Self {
let env: Env = Default::default();
env.mock_all_auths();
let admin = Address::random(&env);
let did = String::from_slice(&env, "did:chaincerts:5ppl9sm47frl0tpj7g3lp6eo");
let admin = Address::generate(&env);
let did = String::from_str(&env, "did:chaincerts:5ppl9sm47frl0tpj7g3lp6eo");
let dids = vec![&env, did.clone()];
let issuer = Address::random(&env);
let issuer = Address::generate(&env);

let contract = VaultContractClient::new(&env, &env.register_contract(None, VaultContract));
VaultContractTest {
Expand All @@ -38,9 +38,9 @@ pub struct VCVaultContractTest {
}

pub fn get_vc_setup(env: &Env) -> VCVaultContractTest {
let vc_id = String::from_slice(env, "vc_id");
let vc_data = String::from_slice(env, "vc_data");
let issuance_contract_address = Address::random(env);
let vc_id = String::from_str(env, "vc_id");
let vc_data = String::from_str(env, "vc_data");
let issuance_contract_address = Address::generate(env);

VCVaultContractTest {
vc_id,
Expand Down
16 changes: 9 additions & 7 deletions vc_issuance_contract/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ use soroban_sdk::{
contract, contractimpl, contractmeta, map, panic_with_error, Address, Env, Map, String, Vec,
};

const LEDGERS_THRESHOLD: u32 = 1;
const LEDGERS_TO_EXTEND: u32 = 535_000;
// MAXIMUM ENTRY TTL:
// 31 days, 12 ledger close per minute.
// (12 * 60 * 24 * 31) - 1
const LEDGERS_TO_EXTEND: u32 = 535_679;
const DEFAULT_AMOUNT: u32 = 20;
const MAX_AMOUNT: u32 = 100;

Expand Down Expand Up @@ -40,7 +42,7 @@ impl VCIssuanceTrait for VCIssuanceContract {

e.storage()
.instance()
.bump(LEDGERS_THRESHOLD, LEDGERS_TO_EXTEND);
.extend_ttl(LEDGERS_TO_EXTEND, LEDGERS_TO_EXTEND);
}
fn issue(
e: Env,
Expand Down Expand Up @@ -68,10 +70,10 @@ impl VCIssuanceTrait for VCIssuanceContract {
validate_vc(&e, &vc_id);
let revocations = storage::read_vcs_revocations(&e);

let status_str = String::from_slice(&e, "status");
let since_str = String::from_slice(&e, "since");
let revoked_str = String::from_slice(&e, "revoked");
let valid_str = String::from_slice(&e, "valid");
let status_str = String::from_str(&e, "status");
let since_str = String::from_str(&e, "since");
let revoked_str = String::from_str(&e, "revoked");
let valid_str = String::from_str(&e, "valid");

match revocations.get(vc_id) {
Some(revocation) => map![&e, (status_str, revoked_str), (since_str, revocation.date)],
Expand Down
Loading

0 comments on commit b7a6637

Please sign in to comment.