Skip to content

Commit

Permalink
task: project structure reorg
Browse files Browse the repository at this point in the history
  • Loading branch information
ipapandinas committed Oct 29, 2023
1 parent 59fb556 commit 24f19f6
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 35 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches: ['**']

env:
SINGLE_ASSET_REWARD: "--manifest-path=src/contracts/single_asset_reward/Cargo.toml"
SINGLE_TOKEN: "--manifest-path=contracts/src/token/single/Cargo.toml"

jobs:
build:
Expand All @@ -25,16 +25,16 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: clippy
args: ${{ env.SINGLE_ASSET_REWARD }} -- -D warnings
args: ${{ env.SINGLE_TOKEN }} -- -D warnings

- name: Build
uses: actions-rs/cargo@v1
with:
command: build
args: ${{ env.SINGLE_ASSET_REWARD }}
args: ${{ env.SINGLE_TOKEN }}

- name: Test
uses: actions-rs/cargo@v1
with:
command: test
args: ${{ env.SINGLE_ASSET_REWARD }}
args: ${{ env.SINGLE_TOKEN }}
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Ignore build artifacts from the local tests sub-crate.
target/
debug/

# Ignore backup files creates by cargo fmt.
**/*.rs.bk

# Remove Cargo.lock when creating an executable, leave it for libraries
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
Cargo.lock

.DS_Store
13 changes: 12 additions & 1 deletion src/Cargo.toml → Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ version= "0.1.0"
authors = ["Igor Papandinas", "Leandro Palazzolo"]
edition = "2021"

license = "MIT"
readme = "README.md"
repository = "https://github.com/kudos-ink/contracts"
description = "Kudos Ink smart contracts for automated contribution rewards."
keywords = ["wasm", "smart-contracts", "blockchain", "ink"]
categories = ["no-std", "embedded"]
include = ["Cargo.toml", "src/**/*.rs"]

[dependencies]
ink = { version = "4.3.0", default-features = false }

Expand All @@ -13,9 +21,12 @@ scale-info = { version = "2.6", default-features = false, features = ["derive"],
# OpenBrush dependency
openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", version = "4.0.0-beta", default-features = false, features = ["ownable"] }

# These dependencies
kudos_ink_contracts = { path = "contracts", default-features = false }

[lib]
name = "kudos_ink"
path = "lib.rs"
path = "src/lib.rs"
crate-type = [
"rlib",
]
Expand Down
1 change: 0 additions & 1 deletion src/.gitignore → contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Ignore build artifacts from the local tests sub-crate.
target/
debug/

# Ignore backup files creates by cargo fmt.
**/*.rs.bk
Expand Down
43 changes: 43 additions & 0 deletions contracts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[workspace]
members = ["src/token/single"]

[package]
name = "kudos_ink_contracts"
version= "0.1.0"
authors = ["Igor Papandinas", "Leandro Palazzolo"]
edition = "2021"

license = "MIT"
readme = "README.md"
repository = "https://github.com/kudos-ink/contracts"
description = "Reusable implementations of reward contracts and traits."
keywords = ["wasm", "smart-contracts", "blockchain", "ink"]
categories = ["no-std", "embedded"]
include = ["Cargo.toml", "src/**/*.rs"]

[dependencies]
ink = { version = "4.3.0", default-features = false }

scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true }

# OpenBrush dependency
openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", version = "4.0.0-beta", default-features = false, features = ["ownable"] }

[lib]
name = "kudos_ink_contracts"
path = "src/lib.rs"
crate-type = [
"rlib",
]

[features]
default = ["std"]
std = [
"ink/std",
"scale/std",
"scale-info/std",
# OpenBrush dependency
"openbrush/std",
]
single = []
3 changes: 3 additions & 0 deletions contracts/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#![cfg_attr(not(feature = "std"), no_std, no_main)]

pub mod traits;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "single_asset_reward"
name = "single_token_contract"
version = "0.1.0"
authors = ["Igor Papandinas", "Leandro Palazzolo"]
edition = "2021"
Expand All @@ -13,10 +13,10 @@ scale-info = { version = "2.6", default-features = false, features = ["derive"],
openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", version = "4.0.0-beta", default-features = false, features = ["ownable"] }

# These dependencies
kudos_ink = { path = "../..", default-features = false }
kudos_ink_contracts = { git = "https://github.com/kudos-ink/contracts", branch = "next" }

[lib]
name = "single_asset_reward"
name = "single_token_contract"
path = "lib.rs"

[features]
Expand All @@ -27,6 +27,6 @@ std = [
"scale-info/std",
# OpenBrush dependency
"openbrush/std",
"kudos_ink/std",
"kudos_ink_contracts/std",
]
ink-as-dependency = []
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#[openbrush::implementation(Ownable)]
#[openbrush::contract]
pub mod single_asset_reward {
use kudos_ink::traits::workflow::{WorkflowError, *};
pub mod single_token {
use kudos_ink_contracts::traits::workflow::{WorkflowError, *};
use openbrush::{modifiers, traits::Storage};

use ink::env::hash::{HashOutput, Sha2x256};
Expand All @@ -27,7 +27,7 @@ pub mod single_asset_reward {

#[ink(storage)]
#[derive(Default, Storage)]
pub struct SingleAssetReward {
pub struct SingleToken {
#[storage_field]
ownable: ownable::Data,

Expand Down Expand Up @@ -69,7 +69,7 @@ pub mod single_asset_reward {
reward: Balance,
}

impl Workflow for SingleAssetReward {
impl Workflow for SingleToken {
/// Register the caller as an aspiring contributor.
///
/// Constraint(s):
Expand Down Expand Up @@ -121,7 +121,7 @@ pub mod single_asset_reward {
}
}

impl SingleAssetReward {
impl SingleToken {
/// Constructor that initializes an asset reward for a given workflow
#[ink(constructor)]
pub fn new(workflow: HashValue, reward: Balance) -> Self {
Expand Down Expand Up @@ -291,7 +291,7 @@ pub mod single_asset_reward {
use super::*;

use ink::env::test::EmittedEvent;
type Event = <SingleAssetReward as ::ink::reflect::ContractEventBase>::Type;
type Event = <SingleToken as ::ink::reflect::ContractEventBase>::Type;

/// We test if the constructor does its job.
#[ink::test]
Expand All @@ -306,7 +306,7 @@ pub mod single_asset_reward {
fn register_identity_works() {
let accounts = default_accounts();
let mut contract = create_contract(1u128, 1u128);
let bob_identity = SingleAssetReward::hash("bobby".as_bytes());
let bob_identity = SingleToken::hash("bobby".as_bytes());
set_next_caller(accounts.bob);
assert_eq!(
contract.register_identity(bob_identity),
Expand Down Expand Up @@ -335,7 +335,7 @@ pub mod single_asset_reward {
fn already_registered_identity_fails() {
let accounts = default_accounts();
let mut contract = create_contract(1u128, 1u128);
let identity = SingleAssetReward::hash("bobby".as_bytes());
let identity = SingleToken::hash("bobby".as_bytes());
set_next_caller(accounts.bob);
let _ = contract.register_identity(identity);
assert_eq!(
Expand All @@ -348,7 +348,7 @@ pub mod single_asset_reward {
fn approve_works() {
let accounts = default_accounts();
let mut contract = create_contract(1u128, 1u128);
let identity = SingleAssetReward::hash("bobby".as_bytes());
let identity = SingleToken::hash("bobby".as_bytes());
set_next_caller(accounts.bob);
let _ = contract.register_identity(identity);

Expand Down Expand Up @@ -381,7 +381,7 @@ pub mod single_asset_reward {
fn only_contract_owner_can_approve() {
let accounts = default_accounts();
let mut contract = create_contract(1u128, 1u128);
let identity = SingleAssetReward::hash("bobby".as_bytes());
let identity = SingleToken::hash("bobby".as_bytes());
set_next_caller(accounts.bob);
let _ = contract.register_identity(identity);

Expand All @@ -396,8 +396,8 @@ pub mod single_asset_reward {
fn already_approved_contribution_fails() {
let accounts = default_accounts();
let mut contract = create_contract(1u128, 1u128);
let identity = SingleAssetReward::hash("bobby".as_bytes());
let identity2 = SingleAssetReward::hash("bobby2".as_bytes());
let identity = SingleToken::hash("bobby".as_bytes());
let identity2 = SingleToken::hash("bobby2".as_bytes());
set_next_caller(accounts.bob);
let _ = contract.register_identity(identity);

Expand All @@ -415,8 +415,8 @@ pub mod single_asset_reward {
fn approve_unknown_contributor_identity_fails() {
let accounts = default_accounts();
let mut contract = create_contract(1u128, 1u128);
let identity = SingleAssetReward::hash("bobby".as_bytes());
let identity2 = SingleAssetReward::hash("bobby2".as_bytes());
let identity = SingleToken::hash("bobby".as_bytes());
let identity2 = SingleToken::hash("bobby2".as_bytes());
set_next_caller(accounts.bob);
let _ = contract.register_identity(identity);

Expand All @@ -432,7 +432,7 @@ pub mod single_asset_reward {
fn can_claim_works() {
let accounts = default_accounts();
let mut contract = create_contract(1u128, 1u128);
let identity = SingleAssetReward::hash("bobby".as_bytes());
let identity = SingleToken::hash("bobby".as_bytes());
set_next_caller(accounts.bob);
let _ = contract.register_identity(identity);

Expand All @@ -452,7 +452,7 @@ pub mod single_asset_reward {
let accounts = default_accounts();
let single_reward = 1u128;
let mut contract = create_contract(1u128, single_reward);
let identity = SingleAssetReward::hash("bobby".as_bytes());
let identity = SingleToken::hash("bobby".as_bytes());
set_next_caller(accounts.bob);
let _ = contract.register_identity(identity);

Expand Down Expand Up @@ -504,7 +504,7 @@ pub mod single_asset_reward {
fn cannot_claim_unknown_contribution() {
let accounts = default_accounts();
let mut contract = create_contract(1u128, 1u128);
let identity = SingleAssetReward::hash("bobby".as_bytes());
let identity = SingleToken::hash("bobby".as_bytes());
set_next_caller(accounts.bob);
let _ = contract.register_identity(identity);

Expand All @@ -523,7 +523,7 @@ pub mod single_asset_reward {
fn cannot_claim_if_not_contributor() {
let accounts = default_accounts();
let mut contract = create_contract(1u128, 1u128);
let identity = SingleAssetReward::hash("bobby".as_bytes());
let identity = SingleToken::hash("bobby".as_bytes());
set_next_caller(accounts.eve);
let _ = contract.register_identity(identity);

Expand All @@ -542,7 +542,7 @@ pub mod single_asset_reward {
fn cannot_claim_already_claimed_reward() {
let accounts = default_accounts();
let mut contract = create_contract(1u128, 1u128);
let identity = SingleAssetReward::hash("bobby".as_bytes());
let identity = SingleToken::hash("bobby".as_bytes());
set_next_caller(accounts.bob);
let _ = contract.register_identity(identity);

Expand Down Expand Up @@ -580,14 +580,14 @@ pub mod single_asset_reward {
.expect("Cannot get account balance")
}

/// Creates a new instance of `SingleAssetReward` with `initial_balance`.
/// Creates a new instance of `SingleToken` with `initial_balance`.
///
/// Returns the `contract_instance`.
fn create_contract(initial_balance: Balance, reward: Balance) -> SingleAssetReward {
fn create_contract(initial_balance: Balance, reward: Balance) -> SingleToken {
let accounts = default_accounts();
set_next_caller(accounts.alice);
set_balance(contract_id(), initial_balance);
SingleAssetReward::new([0; 32], reward)
SingleToken::new([0; 32], reward)
}

fn decode_events(emittend_events: Vec<EmittedEvent>) -> Vec<Event> {
Expand Down
File renamed without changes.
2 changes: 0 additions & 2 deletions src/traits/workflow.rs → contracts/src/traits/workflow.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use openbrush::{contracts::traits::ownable::*, modifiers};

#[cfg(feature = "std")]

/// Type alias for hashes.
pub type HashValue = [u8; 32];

Expand Down
7 changes: 7 additions & 0 deletions kudos-contracts.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"settings": {
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer"
}
}
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#![cfg_attr(not(feature = "std"), no_std, no_main)]

pub mod traits;
pub use kudos_ink_contracts as contracts;

0 comments on commit 24f19f6

Please sign in to comment.