Skip to content

Commit

Permalink
add sui move test
Browse files Browse the repository at this point in the history
  • Loading branch information
CocDap committed Nov 19, 2024
1 parent cf06f2f commit e78acfc
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
81 changes: 81 additions & 0 deletions pages/hello_move/hello_world_move.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,87 @@ Transaction Digest: 4D9a4ZDxfKKPcwwKxj6Ei8TjhZoeW4q3ryTifs9cusTZ
</details>


## Chạy test

Chúng ta cần thêm một số đoạn code ( bạn đừng lo đoạn code này , section tiếp theo mình giới thiệu chi tiết hơn)

+ Thêm hàm `get_text()` vào module `hello_world`

```rust

// sources/hello_world.move

public fun get_text(hello: &HelloWorldObject) : String {
hello.text

}

```

+ Thêm hàm `test_hello_world()` vào module `hello_world_tests`

```rust
// tests/hello_world_tests.move

#[test_only]
module hello_world::hello_world_tests;

#[test]
fun test_hello_world() {
use sui::test_scenario;
use sui::test_utils::assert_eq;
use hello_world::hello_world::{HelloWorldObject, hello_world};
use std::string;
let dummy_address = @0xCAFE;

// First transaction executed by initial owner to create the sword
let mut scenario = test_scenario::begin(dummy_address);
{
// Create hello world
hello_world( scenario.ctx());



};

scenario.next_tx(dummy_address);
{
let hello = scenario.take_from_sender<HelloWorldObject>();
let text = hello.get_text();
std::debug::print(&text);
assert_eq(text, string::utf8(b"Hello World!"));

scenario.return_to_sender(hello)
};

scenario.end();

}

```

+ Chạy command để test smart contract


```bash
sui move test
```


+ Kết quả


```bash
INCLUDING DEPENDENCY Sui
INCLUDING DEPENDENCY MoveStdlib
BUILDING hello_world
Running Move unit tests
[debug] "Hello World!"
[ PASS ] hello_world::hello_world_tests::test_hello_world
Test result: OK. Total tests: 1; passed: 1; failed: 0
```





Expand Down
7 changes: 7 additions & 0 deletions pages/hello_move/sui_cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ sui client new-address ed25519
╰────────────────┴───────────────────────────────────────────────────────────────────────────────╯
```

### Switch address

```bash
sui client switch --address <địa chỉ>
```




## Faucet coins cho address
Expand Down

0 comments on commit e78acfc

Please sign in to comment.