forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hardening] make get_total_sui look inside vectors
Fixing a silly bug that makes the conservation checks fail if a coin flows into or out of a vector
- Loading branch information
1 parent
5679d63
commit 0b909e3
Showing
3 changed files
with
66 additions
and
6 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
crates/sui-adapter-transactional-tests/tests/sui/coin_in_vec.exp
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,15 @@ | ||
processed 4 tasks | ||
|
||
init: | ||
A: object(103) | ||
|
||
task 1 'publish'. lines 6-32: | ||
created: object(105), object(106) | ||
written: object(104) | ||
|
||
task 2 'run'. lines 34-34: | ||
written: object(105), object(107) | ||
deleted: object(104) | ||
|
||
task 3 'run'. lines 36-36: | ||
written: object(104), object(105), object(108) |
36 changes: 36 additions & 0 deletions
36
crates/sui-adapter-transactional-tests/tests/sui/coin_in_vec.move
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,36 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//# init --addresses test=0x0 --accounts A | ||
|
||
//# publish --sender A | ||
|
||
module test::coin_in_vec { | ||
use std::vector; | ||
use sui::coin::Coin; | ||
use sui::object::{Self, UID}; | ||
use sui::sui::SUI; | ||
use sui::transfer; | ||
use sui::tx_context::{Self, TxContext}; | ||
|
||
struct Wrapper has key { | ||
id: UID, | ||
coins: vector<Coin<SUI>>, | ||
} | ||
|
||
fun init(ctx: &mut TxContext) { | ||
transfer::transfer(Wrapper { id: object::new(ctx), coins: vector[] }, tx_context::sender(ctx)); | ||
} | ||
|
||
public fun deposit(wrapper: &mut Wrapper, c: Coin<SUI>) { | ||
vector::push_back(&mut wrapper.coins, c) | ||
} | ||
|
||
public fun withdraw(wrapper: &mut Wrapper, ctx: &mut TxContext) { | ||
transfer::public_transfer(vector::pop_back(&mut wrapper.coins), tx_context::sender(ctx)) | ||
} | ||
} | ||
|
||
//# run test::coin_in_vec::deposit --args --args object(105) object(104) --sender A | ||
|
||
//# run test::coin_in_vec::withdraw --args object(105) --sender A |
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