Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add assertion in stake to StakeToSBTPlugin::stake while the lock ti… #117

Merged
merged 3 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
jolestar marked this conversation as resolved.
Show resolved Hide resolved

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