-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from EmmanuelAR/feat/donator_test
[feat] Add donators contract tests
- Loading branch information
Showing
7 changed files
with
113 additions
and
11 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Go Stark Me - Backend Setup 💻 | ||
|
||
### Steps to Run the Backend 🥳 | ||
|
||
1. **Navigate to the Contracts Directory 🔍** | ||
```bash | ||
cd gostarkme/contracts | ||
2. **Compile gostarkme backend 🛠️** | ||
```bash | ||
scarb build | ||
3. **Run gostarkme unit test ✅** | ||
```bash | ||
snforge test | ||
4. **Run code formatter 📝** | ||
```bash | ||
scarb fmt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
mod constants; | ||
pub mod constants; | ||
// FUND | ||
mod fund; | ||
mod fundManager; | ||
pub mod fund; | ||
pub mod fundManager; | ||
// DONATOR | ||
mod donatorManager; | ||
mod donator; | ||
pub mod donatorManager; | ||
pub mod donator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// ************************************************************************* | ||
// DONATOR TEST | ||
// ************************************************************************* | ||
use starknet::{ContractAddress, contract_address_const}; | ||
|
||
use snforge_std::{declare, ContractClassTrait}; | ||
use openzeppelin::utils::serde::SerializedAppend; | ||
|
||
use gostarkme::donator::IDonatorDispatcher; | ||
use gostarkme::donator::IDonatorDispatcherTrait; | ||
|
||
fn OWNER() -> ContractAddress { | ||
contract_address_const::<'OWNER'>() | ||
} | ||
|
||
fn __setup__() -> ContractAddress { | ||
let contract = declare("Donator"); | ||
let mut calldata: Array<felt252> = array![]; | ||
calldata.append_serde(OWNER()); | ||
contract.deploy(@calldata).unwrap() | ||
} | ||
|
||
// ************************************************************************* | ||
// TEST | ||
// ************************************************************************* | ||
#[test] | ||
fn test_get_owner() { | ||
let contract_address = __setup__(); | ||
let dispatcher = IDonatorDispatcher { contract_address }; | ||
let owner = dispatcher.getOwner(); | ||
assert(owner == OWNER(), 'Invalid owner'); | ||
} | ||
|
||
#[test] | ||
fn test_get_level() { | ||
let contract_address = __setup__(); | ||
let dispatcher = IDonatorDispatcher { contract_address }; | ||
let level = dispatcher.getLevel(); | ||
assert(level == 1, 'Invalid level'); | ||
} | ||
|
||
#[test] | ||
fn test_get_total_stark_donations() { | ||
let contract_address = __setup__(); | ||
let dispatcher = IDonatorDispatcher { contract_address }; | ||
let total_stark_donations = dispatcher.getTotalStarkDonations(); | ||
assert(total_stark_donations == 0, 'Invalid total stark donations'); | ||
} | ||
|
||
#[test] | ||
fn test_get_max_stark_donations_to_next_level() { | ||
let contract_address = __setup__(); | ||
let dispatcher = IDonatorDispatcher { contract_address }; | ||
let max_stark_donations_to_next_level = dispatcher.getMaxStarkDonationsToNextLevel(); | ||
assert(max_stark_donations_to_next_level == 10, 'Invalid total stark donations'); | ||
} | ||
|
||
#[test] | ||
fn test_update_donator_values() { | ||
let contract_address = __setup__(); | ||
let dispatcher = IDonatorDispatcher { contract_address }; | ||
dispatcher.updateDonatorValues(5); | ||
let level = dispatcher.getLevel(); | ||
let total_stark_donations = dispatcher.getTotalStarkDonations(); | ||
assert(level == 1, 'Invalid level'); | ||
assert(total_stark_donations == 5, 'Invalid total stark donations'); | ||
dispatcher.updateDonatorValues(5); | ||
let level = dispatcher.getLevel(); | ||
assert(level == 1, 'Invalid level'); | ||
dispatcher.updateDonatorValues(1); | ||
let level = dispatcher.getLevel(); | ||
let total_stark_donations = dispatcher.getTotalStarkDonations(); | ||
let max_stark_donations_to_next_level = dispatcher.getMaxStarkDonationsToNextLevel(); | ||
assert(level == 2, 'Invalid level'); | ||
assert(total_stark_donations == 11, 'Invalid total stark donations'); | ||
assert(max_stark_donations_to_next_level == 20, 'Invalid total stark donations'); | ||
} |