Skip to content

Commit

Permalink
Merge pull request #16 from Entropy-Foundation/add-back-aggregator-test
Browse files Browse the repository at this point in the history
Add back aggregator tests and fix the errors
  • Loading branch information
axiongsupra authored Jun 7, 2024
2 parents fc016b5 + 40b0c97 commit 3aaf2c3
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions aptos-move/framework/supra-framework/tests/aggregator_tests.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#[test_only]
module supra_framework::aggregator_tests {

use supra_framework::aggregator;
use supra_framework::aggregator_factory;

#[test(account = @supra_framework)]
fun test_can_add_and_sub_and_read(account: signer) {
aggregator_factory::initialize_aggregator_factory_for_test(&account);
let aggregator = aggregator_factory::create_aggregator(&account, 1000);

aggregator::add(&mut aggregator, 12);
assert!(aggregator::read(&aggregator) == 12, 0);

aggregator::add(&mut aggregator, 3);
assert!(aggregator::read(&aggregator) == 15, 0);

aggregator::add(&mut aggregator, 3);
aggregator::add(&mut aggregator, 2);
aggregator::sub(&mut aggregator, 20);
assert!(aggregator::read(&aggregator) == 0, 0);

aggregator::add(&mut aggregator, 1000);
aggregator::sub(&mut aggregator, 1000);

aggregator::destroy(aggregator);
}

#[test(account = @supra_framework)]
#[expected_failure(abort_code = 0x020001, location = supra_framework::aggregator)]
fun test_overflow(account: signer) {
aggregator_factory::initialize_aggregator_factory_for_test(&account);
let aggregator = aggregator_factory::create_aggregator(&account, 10);

// Overflow!
aggregator::add(&mut aggregator, 12);

aggregator::destroy(aggregator);
}

#[test(account = @supra_framework)]
#[expected_failure(abort_code = 0x020002, location = supra_framework::aggregator)]
fun test_underflow(account: signer) {
aggregator_factory::initialize_aggregator_factory_for_test(&account);
let aggregator = aggregator_factory::create_aggregator(&account, 10);

// Underflow!
aggregator::sub(&mut aggregator, 100);
aggregator::add(&mut aggregator, 100);

aggregator::destroy(aggregator);
}
}

0 comments on commit 3aaf2c3

Please sign in to comment.