Skip to content

Commit

Permalink
fix(devx): Rebase and fix conflicts.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-tortora committed Aug 26, 2024
1 parent 4be27bf commit 2222c24
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 874 deletions.
175 changes: 92 additions & 83 deletions docs/content/developer/getting-started/build-test.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ iota move test
If you haven't added any tests, you should see the following output.

```shell
BUILDING IOTA
BUILDING MoveStdlib
INCLUDING DEPENDENCY Iota
INCLUDING DEPENDENCY MoveStdlib
BUILDING my_first_package
Running Move unit tests
Test result: OK. Total tests: 0; passed: 0; failed: 0
Expand All @@ -62,24 +62,23 @@ You can add your first unit test by copying the following public test function a

```move
#[test]
public fun test_sword_create() {
// Create a dummy TxContext for testing
let ctx = tx_context::dummy();
public fun test_sword() {
// Create a dummy TxContext for testing.
let mut ctx = tx_context::dummy();
// Create a sword
// Create a sword.
let sword = Sword {
id: object::new(&mut ctx),
magic: 42,
strength: 7,
};
// Check if accessor functions return correct values
// Check if accessor functions return correct values.
assert!(magic(&sword) == 42 && strength(&sword) == 7, 1);
}
```

The unit test function `test_sword_create()` will:
The unit test function `test_sword()` will:

1. Create a dummy instance of the `TxContext` struct and assign it to `ctx`.
2. Create a sword object that uses `ctx` to create a unique identifier (`id`), and assign `42` to the `magic` parameter, and `7` to `strength`.
Expand All @@ -99,22 +98,22 @@ If you run the `iota move test` command, you might receive the following error m

```
error[E06001]: unused value without 'drop'
┌─ ./sources/my_module.move:60:65
4 │ struct Sword has key, store {
│ ----- To satisfy the constraint, the 'drop' ability would need to be added here
·
27 │ let sword = Sword {
┌─ sources/my_module.move:55:65
4 │ public struct Sword has key, store {
----- To satisfy the constraint, the 'drop' ability would need to be added here
·
48 │ let sword = Sword {
│ ----- The local variable 'sword' still contains a value. The value does not have the 'drop' ability and must be consumed before the function returns
│ ╭─────────────────────'
28 │ │ id: object::new(&mut ctx),
29 │ │ magic: 42,
30 │ │ strength: 7,
31 │ │ };
│ ╰─────────' The type 'MyFirstPackage::my_module::Sword' does not have the ability 'drop'
49 │ │ id: object::new(&mut ctx),
50 │ │ magic: 42,
51 │ │ strength: 7,
52 │ │ };
│ ╰─────────' The type 'my_first_package::my_module::Sword' does not have the ability 'drop'
· │
34 │ assert!(magic(&sword) == 42 && strength(&sword) == 7, 1);
^ Invalid return
55 │ assert!(magic(&sword) == 42 && strength(&sword) == 7, 1);
```

The compilation error provides all the necessary information to help you [debug](debug.mdx) your module.
Expand All @@ -130,19 +129,19 @@ use iota::transfer;
Now, you can add the following after the function's `!assert` call to transfer the `sword` to a freshly created dummy address:

```move
// Create a dummy address and transfer the sword
// Create a dummy address and transfer the sword.
let dummy_address = @0xCAFE;
transfer::transfer(sword, dummy_address);
```

Run the test command again. Now the output shows a single successful test has run:

```shell
BUILDING MoveStdlib
BUILDING IOTA
INCLUDING DEPENDENCY Iota
INCLUDING DEPENDENCY MoveStdlib
BUILDING my_first_package
Running Move unit tests
[ PASS ] 0x0::my_module::test_sword_create
[ PASS ] 0x0::my_module::test_sword
Test result: OK. Total tests: 1; passed: 1; failed: 0
```

Expand Down Expand Up @@ -191,24 +190,20 @@ The `Scenario` instance will emulate the IOTA object storage with an object pool
You should update the `my_module.move` file to include entry functions callable from IOTA that implement `sword` creation and transfer. You can add these after the accessor functions.

```move
entry fun sword_create(magic: u64, strength: u64, recipient: address, ctx: &mut TxContext) {
// create a sword
public fun create_sword(magic: u64, strength: u64, recipient: address, ctx: &mut TxContext) {
// Create a sword.
let sword = Sword {
id: object::new(ctx),
magic: magic,
strength: strength,
};
// transfer the sword
// Transfer the sword.
transfer::transfer(sword, recipient);
}
entry fun sword_transfer(sword: Sword, recipient: address, _ctx: &mut TxContext) {
// transfer the sword
public fun sword_transfer(sword: Sword, recipient: address, _ctx: &mut TxContext) {
// Transfer the sword.
transfer::public_transfer(sword, recipient);
}
```

Expand All @@ -219,43 +214,41 @@ With this code, you have enabled creating and transferring a `sword`. Since thes
fun test_sword_transactions() {
use iota::test_scenario;
// create test addresses representing users
// Create test addresses representing users.
let admin = @0xBABE;
let initial_owner = @0xCAFE;
let final_owner = @0xFACE;
// first transaction to emulate module initialization
let scenario_val = test_scenario::begin(admin);
// First transaction to emulate module initialization.
let mut scenario_val = test_scenario::begin(admin);
let scenario = &mut scenario_val;
{
init(test_scenario::ctx(scenario));
};
// second transaction executed by admin to create the sword
// Second transaction executed by admin to create a sword.
test_scenario::next_tx(scenario, admin);
{
// create the sword and transfer it to the initial owner
sword_create(42, 7, initial_owner, test_scenario::ctx(scenario));
// Create the sword and transfer it to the initial owner.
create_sword(42, 7, initial_owner, test_scenario::ctx(scenario));
};
// third transaction executed by the initial sword owner
// Third transaction executed by the initial sword owner.
test_scenario::next_tx(scenario, initial_owner);
{
// extract the sword owned by the initial owner
// Extract the sword owned by the initial owner.
let sword = test_scenario::take_from_sender<Sword>(scenario);
// transfer the sword to the final owner
// Transfer the sword to the final owner.
sword_transfer(sword, final_owner, test_scenario::ctx(scenario))
};
// fourth transaction executed by the final sword owner
// Fourth transaction executed by the final sword owner.
test_scenario::next_tx(scenario, final_owner);
{
// extract the sword owned by the final owner
// Extract the sword owned by the final owner.
let sword = test_scenario::take_from_sender<Sword>(scenario);
// verify that the sword has expected properties
// Verify that the sword has expected properties.
assert!(magic(&sword) == 42 && strength(&sword) == 7, 1);
// return the sword to the object pool
// Return the sword to the object pool
test_scenario::return_to_sender(scenario, sword)
// or uncomment the line below to destroy the sword instead
// or uncomment the line below to destroy the sword instead.
// test_utils::destroy(sword)
};
test_scenario::end(scenario_val);
Expand Down Expand Up @@ -338,11 +331,11 @@ This guide only covers the basics. You should check out the available functions
If you run the test command again, you should see two successful tests for the module:

```shell
BUILDING IOTA
BUILDING MoveStdlib
INCLUDING DEPENDENCY Iota
INCLUDING DEPENDENCY MoveStdlib
BUILDING my_first_package
Running Move unit tests
[ PASS ] 0x0::my_module::test_sword_create
[ PASS ] 0x0::my_module::test_sword
[ PASS ] 0x0::my_module::test_sword_transactions
Test result: OK. Total tests: 2; passed: 2; failed: 0
```
Expand All @@ -360,14 +353,12 @@ If this were an actual module, you should replace the `create_sword` function wi
:::

```move
/// Constructor for creating swords
public fun new_sword(
forge: &mut Forge,
magic: u64,
strength: u64,
ctx: &mut TxContext,
): Sword {
/// Constructor for creating swords.
public fun new_sword(forge: &mut Forge, magic: u64, strength: u64, ctx: &mut TxContext): Sword {
// Increment the `swords_created` counter.
forge.swords_created = forge.swords_created + 1;
// Create a sword.
Sword {
id: object::new(ctx),
magic: magic,
Expand All @@ -379,36 +370,54 @@ public fun new_sword(
You can now add the following code to the end of the module to test the module initializer using the `test_scenario` module by calling the module's `init` function and then asserting the number of swords is zero:

```move
#[test_only] use iota::test_scenario as ts;
#[test_only] const ADMIN: address = @0xAD;
#[test]
public fun test_module_init() {
let ts = ts::begin(@0x0);
fun test_sword_transactions() {
use iota::test_scenario;
// first transaction to emulate module initialization.
// Create test addresses representing users.
let admin = @0xBABE;
let initial_owner = @0xCAFE;
let final_owner = @0xFACE;
// First transaction to emulate module initialization.
let mut scenario_val = test_scenario::begin(admin);
let scenario = &mut scenario_val;
{
ts::next_tx(&mut ts, ADMIN);
init(ts::ctx(&mut ts));
init(test_scenario::ctx(scenario));
};
// second transaction to check if the forge has been created
// and has initial value of zero swords created
// Second transaction executed by admin to create a sword.
test_scenario::next_tx(scenario, admin);
{
ts::next_tx(&mut ts, ADMIN);
// extract the Forge object
let forge: Forge = ts::take_from_sender(&mut ts);
let mut forge = test_scenario::take_from_sender<Forge>(scenario);
// verify number of created swords
assert!(swords_created(&forge) == 0, 1);
// Create the sword and transfer it to the initial owner.
let sword = new_sword(&mut forge, 42, 7, test_scenario::ctx(scenario));
transfer::public_transfer(sword, initial_owner);
// return the Forge object to the object pool
ts::return_to_sender(&mut ts, forge);
// Return the forge to the sender.
test_scenario::return_to_sender(scenario, forge);
};
ts::end(ts);
// Third transaction executed by the initial sword owner.
test_scenario::next_tx(scenario, initial_owner);
{
// Extract the sword owned by the initial owner.
let sword = test_scenario::take_from_sender<Sword>(scenario);
// Transfer the sword to the final owner.
sword_transfer(sword, final_owner, test_scenario::ctx(scenario))
};
// Fourth transaction executed by the final sword owner.
test_scenario::next_tx(scenario, final_owner);
{
// Extract the sword owned by the final owner.
let sword = test_scenario::take_from_sender<Sword>(scenario);
// Verify that the sword has expected properties.
assert!(magic(&sword) == 42 && strength(&sword) == 7, 1);
// Return the sword to the object pool
test_scenario::return_to_sender(scenario, sword)
// or uncomment the line below to destroy the sword instead.
// test_utils::destroy(sword)
};
test_scenario::end(scenario_val);
}
```

Expand Down
16 changes: 8 additions & 8 deletions docs/content/developer/getting-started/client-tssdk.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ ReactDOM.createRoot(document.getElementById('root')!).render(
```
<AlphaNet />

### `IOTAClientProvider`
### `IotaClientProvider`

Next, set up the `IOTAClientProvider`. This `Provider` delivers an `IOTAClient` instance from `@iota/iota.js` to all the
Next, set up the `IotaClientProvider`. This `Provider` delivers an `IOTAClient` instance from `@iota/iota.js` to all the
hooks in dApp Kit. This provider manages which network dApp Kit connects to and can accept configurations for multiple
networks. In this exercise, you'll connect to `devnet`.

```ts
import { IOTAClientProvider } from '@iota/dapp-kit';
import { IotaClientProvider } from '@iota/dapp-kit';
import { getFullnodeUrl } from '@iota/iota-sdk/client';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';

Expand All @@ -117,9 +117,9 @@ const networks = {
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<QueryClientProvider client={queryClient}>
<IOTAClientProvider networks={networks} defaultNetwork="devnet">
<IotaClientProvider networks={networks} defaultNetwork="devnet">
<App />
</IOTAClientProvider>
</IotaClientProvider>
</QueryClientProvider>
</React.StrictMode>,
);
Expand All @@ -133,7 +133,7 @@ Finally, set up the `WalletProvider` from `@iota/dapp-kit`, and import styles fo
```ts
import '@iota/dapp-kit/dist/index.css';

import { IOTAClientProvider, WalletProvider } from '@iota/dapp-kit';
import { IotaClientProvider, WalletProvider } from '@iota/dapp-kit';
import { getFullnodeUrl } from '@iota/iota-sdk/client';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';

Expand All @@ -146,11 +146,11 @@ const networks = {
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<QueryClientProvider client={queryClient}>
<IOTAClientProvider networks={networks} defaultNetwork="devnet">
<IotaClientProvider networks={networks} defaultNetwork="devnet">
<WalletProvider>
<App />
</WalletProvider>
</IOTAClientProvider>
</IotaClientProvider>
</QueryClientProvider>
</React.StrictMode>,
);
Expand Down
5 changes: 2 additions & 3 deletions docs/content/developer/getting-started/create-a-package.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ In `.toml` files, use the hash mark (`#`) to denote a comment.
```toml title="my_first_package/Move.toml"
[package]
name = "my_first_package"

# edition = "2024.beta " # To use the Move 2024 edition, currently in beta
edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move
# license = "" # e.g., "MIT", "GPL", "Apache 2.0"
# authors = ["..."] # e.g., ["Joe Smith ([email protected])", "John Snow ([email protected])"]

[dependencies]
IOTA = { git = "https://github.com/iotaledger/iota.git", subdir = "crates/iota-framework/packages/iota-framework", rev = "framework/testnet" }
Iota = { git = "https://github.com/iotaledger/iota.git", subdir = "crates/iota-framework/packages/iota-framework", rev = "framework/testnet" }

# For remote import, use the `{ git = "...", subdir = "...", rev = "..." }`.
# Revision can be a branch, a tag, and a commit hash.
Expand Down
Loading

0 comments on commit 2222c24

Please sign in to comment.