Skip to content

Commit

Permalink
add assertion in stake to StakeToSBTPlugin::stake while the lock ti… (
Browse files Browse the repository at this point in the history
#117)

* add assertion in stake to `StakeToSBTPlugin::stake` while the lock time not match any config

* add assertion in stake to `StakeToSBTPlugin::stake` while the lock time not match any config
  • Loading branch information
welbon committed Sep 13, 2022
1 parent 4c32fda commit 08928d4
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 45 deletions.
54 changes: 27 additions & 27 deletions integration-tests/daospace/stake_to_sbt_plugin.exp
Original file line number Diff line number Diff line change
@@ -1,34 +1,18 @@
processed 17 tasks

task 4 'run'. lines 9-17:
{
"gas_used": 17743,
"status": {
"MoveAbort": {
"location": {
"Module": {
"address": "0x00000000000000000000000000000001",
"name": "Block"
}
},
"abort_code": "5382"
}
}
}

task 6 'run'. lines 61-69:
task 5 'run'. lines 61-69:
{
"gas_used": 1672577,
"status": "Executed"
}

task 7 'run'. lines 71-107:
task 6 'run'. lines 71-107:
{
"gas_used": 654799,
"gas_used": 569552,
"status": "Executed"
}

task 8 'run'. lines 109-120:
task 7 'run'. lines 109-120:
{
"gas_used": 38208,
"status": {
Expand All @@ -44,32 +28,48 @@ task 8 'run'. lines 109-120:
}
}

task 10 'run'. lines 124-137:
task 9 'run'. lines 124-137:
{
"gas_used": 86008,
"status": "Executed"
}

task 11 'run'. lines 139-155:
task 10 'run'. lines 139-155:
{
"gas_used": 422064,
"gas_used": 336817,
"status": "Executed"
}

task 13 'run'. lines 159-172:
task 12 'run'. lines 159-172:
{
"gas_used": 216758,
"status": "Executed"
}

task 14 'run'. lines 174-190:
task 13 'run'. lines 174-190:
{
"gas_used": 543585,
"gas_used": 458338,
"status": "Executed"
}

task 16 'run'. lines 194-209:
task 15 'run'. lines 194-209:
{
"gas_used": 225723,
"status": "Executed"
}

task 16 'run'. lines 211-222:
{
"gas_used": 307027,
"status": {
"MoveAbort": {
"location": {
"Module": {
"address": "0x00000000000000000000000000000001",
"name": "StakeToSBTPlugin"
}
},
"abort_code": "257793"
}
}
}
35 changes: 24 additions & 11 deletions integration-tests/daospace/stake_to_sbt_plugin.move
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

//# block --author 0x1 --timestamp 86400000

//# run --signers creator
script {
use StarcoinFramework::StdlibUpgradeScripts;

fun upgrade_from_v11_to_v12() {
StdlibUpgradeScripts::upgrade_from_v11_to_v12();
}
}
// check: EXECUTED
// //# run --signers creator
// script {
// use StarcoinFramework::StdlibUpgradeScripts;
//
// fun upgrade_from_v11_to_v12() {
// StdlibUpgradeScripts::upgrade_from_v11_to_v12();
// }
// }
// // check: EXECUTED

//# publish
module creator::XDAO {
Expand Down Expand Up @@ -117,7 +117,7 @@ script {
StakeToSBTPlugin::unstake_all<XDAO::X, STC::STC>(Signer::address_of(&sender));
}
}
// check: ABORTED
// check: ABORTED, 257025

//# block --author 0x1 --timestamp 87400000

Expand Down Expand Up @@ -206,4 +206,17 @@ script {
assert!(StakeToSBTPlugin::query_stake_count<XDAO::X, STC::STC>(sender_addr) <= 0, 10006);
}
}
// check: CHECKED
// check: CHECKED

//# run --signers alice
script {
use creator::XDAO;
use StarcoinFramework::StakeToSBTPlugin;
use StarcoinFramework::STC;
use StarcoinFramework::Account;

fun test_block_time_not_exact_match(sender: signer) {
StakeToSBTPlugin::stake<XDAO::X, STC::STC>(&sender, Account::withdraw<STC::STC>(&sender, 100), 50);
}
}
// check: ABORTED, 257793
15 changes: 8 additions & 7 deletions sources/daospaceplugin/StakeToSBTPlugin.move
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module StarcoinFramework::StakeToSBTPlugin {
const ERR_PLUGIN_STILL_LOCKED: u64 = 1004;
const ERR_PLUGIN_CONFIG_INIT_REPEATE: u64 = 1005;
const ERR_PLUGIN_ITEM_CANT_FOUND: u64 = 1006;
const ERR_PLUGIN_NO_MATCH_LOCKTIME: u64 = 1007;

struct StakeToSBTPlugin has store, drop {}

Expand Down Expand Up @@ -174,13 +175,9 @@ module StarcoinFramework::StakeToSBTPlugin {
};

let weight_opt = get_sbt_weight<DAOT, TokenT>(lock_time);
let weight = if (Option::is_none(&weight_opt)) {
1
} else {
Option::destroy_some(weight_opt)
};
assert!(Option::is_some(&weight_opt), Errors::invalid_state(ERR_PLUGIN_NO_MATCH_LOCKTIME));

let token_amount = Token::value<TokenT>(&token);
let weight = Option::destroy_some(weight_opt);
let sbt_amount = compute_token_to_sbt(weight, &token);
DAOSpace::increase_member_sbt(&member_cap, sender_addr, sbt_amount);

Expand All @@ -206,7 +203,11 @@ module StarcoinFramework::StakeToSBTPlugin {
dao_id: DAOSpace::dao_id(DAOSpace::dao_address<DAOT>()),
stake_id: id,
token_code: Token::token_code<TokenT>(),
amount: token_amount,
amount:



,
lock_time,
weight,
sbt_amount,
Expand Down

0 comments on commit 08928d4

Please sign in to comment.