Skip to content

Commit

Permalink
[Astra] rename cleanup : make sure the tests are passing[Rust unit an…
Browse files Browse the repository at this point in the history
…d integration tests] (#3)

* update one test

* update multi council test

* update test bounty test

* update test

* cleanup

* complete general tests

* lint fix

* update upgrade test

* lint

* add files

* paths

* update

* update

* remove files

* path

* flow

* update

* update

* update

* update

* copy

* buildg

* update

* update

* update

* update

* update

* update

* update

* update build

* update

* update

* use 1.69.0

* remove build from job

* add more tests

* Apply suggestions from code review

Co-authored-by: sczembor <[email protected]>

* updates

* fix

* lint

---------

Co-authored-by: sczembor <[email protected]>
  • Loading branch information
amityadav0 and sczembor authored Sep 12, 2023
1 parent 8799582 commit 58e7bab
Show file tree
Hide file tree
Showing 20 changed files with 804 additions and 793 deletions.
156 changes: 0 additions & 156 deletions .github/workflows/build.yml

This file was deleted.

56 changes: 34 additions & 22 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
name: Tests
name: Rust

on:
push:
branches:
- master
pull_request:
branches: [master, main]
merge_group:
push:
branches: ["master"]

concurrency:
group: ci-${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true

env:
CARGO_TERM_COLOR: always

jobs:
tests:
strategy:
matrix:
platform: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.platform }}
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v3
- uses: technote-space/[email protected]
with:
PATTERNS: |
**/**.rs
Cargo.lock
- name: Install latest nightly
if: env.GIT_DIFF
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: wasm32-unknown-unknown
toolchain: 1.69.0
override: true
components: rustfmt, clippy

- name: Install wasm32 toolchain
if: env.GIT_DIFF
run: rustup target add wasm32-unknown-unknown
- name: Build
env:
IS_GITHUB_ACTION: true
run: cargo +stable build --workspace --target wasm32-unknown-unknown --release
run: sh build.sh

- name: Run Cargo tests
env:
IS_GITHUB_ACTION: true
run: cargo test --workspace -- --nocapture
- name: Run Ava tests
env:
IS_GITHUB_ACTION: true
run: cd astra && sh test.sh
6 changes: 4 additions & 2 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[workspace]
members = [
"astra-staking",
"astra",
"test-token",
"astra-factory",
"test-token"
"astra-staking",
]

[workspace.package]
Expand Down
6 changes: 3 additions & 3 deletions astra-factory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const FACTORY_OWNER_KEY: &[u8; 5] = b"OWNER";
const CODE_METADATA_KEY: &[u8; 8] = b"METADATA";

// The values used when writing initial data to the storage.
const DAO_CONTRACT_INITIAL_CODE: &[u8] = include_bytes!("../../res/astra.wasm");
const DAO_CONTRACT_INITIAL_CODE: &[u8] = include_bytes!("../../target/wasm32-unknown-unknown/release/astra.wasm");
const DAO_CONTRACT_INITIAL_VERSION: Version = [3, 0];
const DAO_CONTRACT_NO_DATA: &str = "no data";

Expand Down Expand Up @@ -357,7 +357,7 @@ impl AstraFactory {
let storage_metadata = env::storage_read(CODE_METADATA_KEY).expect("INTERNAL_FAIL");
let deserialized_metadata: UnorderedMap<Base58CryptoHash, DaoContractMetadata> =
BorshDeserialize::try_from_slice(&storage_metadata).expect("INTERNAL_FAIL");
return deserialized_metadata.to_vec();
deserialized_metadata.to_vec()
}

fn assert_owner(&self) {
Expand All @@ -371,7 +371,7 @@ impl AstraFactory {

pub fn slice_to_hash(hash: &[u8]) -> Base58CryptoHash {
let mut result: CryptoHash = [0; 32];
result.copy_from_slice(&hash);
result.copy_from_slice(hash);
Base58CryptoHash::from(result)
}

Expand Down
12 changes: 6 additions & 6 deletions astra-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl Contract {
#[init]
pub fn new(owner_id: AccountId, token_id: AccountId, unstake_period: U64) -> Self {
Self {
owner_id: owner_id.into(),
owner_id,
vote_token_id: token_id,
users: LookupMap::new(StorageKeys::Users),
total_amount: 0,
Expand All @@ -89,23 +89,23 @@ impl Contract {
/// If enough tokens and storage, forwards this to owner account.
pub fn delegate(&mut self, account_id: AccountId, amount: U128) -> Promise {
let sender_id = env::predecessor_account_id();
self.internal_delegate(sender_id, account_id.clone().into(), amount.0);
self.internal_delegate(sender_id, account_id.clone(), amount.0);
ext_astra::ext(self.owner_id.clone())
.with_static_gas(GAS_FOR_DELEGATE)
.delegate(
account_id.into(),
account_id,
amount
)
}

/// Remove given amount of delegation.
pub fn undelegate(&mut self, account_id: AccountId, amount: U128) -> Promise {
let sender_id = env::predecessor_account_id();
self.internal_undelegate(sender_id, account_id.clone().into(), amount.0);
self.internal_undelegate(sender_id, account_id.clone(), amount.0);
ext_astra::ext(self.owner_id.clone())
.with_static_gas(GAS_FOR_UNDELEGATE)
.undelegate(
account_id.into(),
account_id,
amount
)
}
Expand Down Expand Up @@ -198,7 +198,7 @@ mod tests {
testing_env!(context.attached_deposit(parse_near!("1 N")).build());
contract.storage_deposit(Some(delegate_from_user.clone()), None);

testing_env!(context.predecessor_account_id(voting_token.clone()).build());
testing_env!(context.predecessor_account_id(voting_token).build());
contract.ft_on_transfer(
delegate_from_user.clone(),
U128(parse_near!("100")),
Expand Down
10 changes: 5 additions & 5 deletions astra-staking/src/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,17 @@ impl Contract {

/// Deposit voting token.
pub fn internal_deposit(&mut self, sender_id: &AccountId, amount: Balance) {
let mut sender = self.internal_get_user(&sender_id);
let mut sender = self.internal_get_user(sender_id);
sender.deposit(amount);
self.save_user(&sender_id, sender);
self.save_user(sender_id, sender);
self.total_amount += amount;
}

/// Withdraw voting token.
pub fn internal_withdraw(&mut self, sender_id: &AccountId, amount: Balance) {
let mut sender = self.internal_get_user(&sender_id);
let mut sender = self.internal_get_user(sender_id);
sender.withdraw(amount);
self.save_user(&sender_id, sender);
self.save_user(sender_id, sender);
assert!(self.total_amount >= amount, "ERR_INTERNAL");
self.total_amount -= amount;
}
Expand All @@ -186,7 +186,7 @@ impl Contract {
) {
let mut sender = self.internal_get_user(&sender_id);
assert!(self.users.contains_key(&delegate_id), "ERR_NOT_REGISTERED");
sender.delegate(delegate_id.clone(), amount);
sender.delegate(delegate_id, amount);
self.save_user(&sender_id, sender);
}

Expand Down
2 changes: 2 additions & 0 deletions astra/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ version = "1.4.0"
[dev-dependencies]
workspaces.workspace = true
near-units.workspace = true
tokio.workspace = true
anyhow.workspace = true
test-token = { path = "../test-token" }
astra-staking = { path = "../astra-staking" }
astra-factory = { path = "../astra-factory" }
Loading

0 comments on commit 58e7bab

Please sign in to comment.