forked from FuelLabs/sway
-
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.
* Create empty token lib * Add todos * Add mint & burn funcs * Add outline of abi, contract and test * It builds * Redeploy to get Id * Add to mod.rs * Add force_transfer() func * Add force_transfer() func * Update color to token_id and redeploy * Apply formatting * Start on tto * fixup * Fix ETH_COLOR to be ETH_ID * Rough out transfer_to_output * It builds * Add notes to test * Add new constants * Switch to local constants * Refactoring * Start cleanup * Clean up temp functions and asm blocks * Update dep paths in toml files * Simplify while loop * Fixup * Remove temp local variables and nested loop * Fixup * Fixup * Formatting * remove redundant abi & contract * Fixup * Update test setup * Update magic number to use bytes instead of bits * Update test token * Update test file types * Fix string to str * Update toml file import * Fix contract_id type * update forc toml * Update test with new balance_of_contract api * Add notes to context.sw * Add core to toml file * Update types in fuel coin abi * Fix test types * Fixup * Fix asm register name * Update the fuelcoin contract deployed id * Fix toml to use local path for development * Update types in balance_of_contract calls * Delete lib-std * Update import paths in toml file * Fix contract id in toml * Use hardcoded contract id in test contract call * Fix import path for std to use git path * Fix import paths in toml files * Rename token_id to asset_id * Fix types in contract calls to use ContractId * Update balance test contract id in toml * Fixup * Add json oracle file for contract * Remove const NAME and just use hardcoded string * Update balance_test_contract id in toml and test * Fixup * Update cargo lock file * Update contract ids * Temp changes to tests * Restore tests * Update contract id again * Remove name func * Minimize pr to just mint function * Fixup * Update contract-id and utxo id * Fix test * Cleanup toml * Add burn function to abi and contract * Update contract id and add burn test * Update test/src/e2e_vm_tests/test_programs/test_fuel_coin_abi/Forc.toml Co-authored-by: John Adler <[email protected]> * Update test/src/e2e_vm_tests/test_programs/test_fuel_coin_abi/Forc.toml Co-authored-by: John Adler <[email protected]> * Update test/src/e2e_vm_tests/test_programs/test_fuel_coin_contract/Forc.toml Co-authored-by: John Adler <[email protected]> * Update test/src/e2e_vm_tests/test_programs/test_fuel_coin_contract/Forc.toml Co-authored-by: John Adler <[email protected]> * Update test/src/e2e_vm_tests/test_programs/token_ops_test/Forc.toml Co-authored-by: John Adler <[email protected]> * Update test/src/e2e_vm_tests/test_programs/token_ops_test/Forc.toml Co-authored-by: John Adler <[email protected]> * Update test/src/e2e_vm_tests/test_programs/token_ops_test/Forc.toml Co-authored-by: John Adler <[email protected]> Co-authored-by: John Adler <[email protected]>
- Loading branch information
Showing
8 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
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
8 changes: 8 additions & 0 deletions
8
test/src/e2e_vm_tests/test_programs/test_fuel_coin_abi/Forc.toml
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,8 @@ | ||
[project] | ||
author = "Fuel Labs <[email protected]>" | ||
license = "Apache-2.0" | ||
name = "test_fuel_coin_abi" | ||
entry = "main.sw" | ||
|
||
[dependencies] | ||
std = { git = "http://github.com/FuelLabs/sway-lib-std", version = "v0.0.1" } |
9 changes: 9 additions & 0 deletions
9
test/src/e2e_vm_tests/test_programs/test_fuel_coin_abi/src/main.sw
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,9 @@ | ||
library test_fuel_coin_abi; | ||
|
||
use std::address::Address; | ||
use std::contract_id::ContractId; | ||
|
||
abi TestFuelCoin { | ||
fn mint(gas: u64, coins: u64, asset_id: b256, mint_amount: u64); | ||
fn burn(gas: u64, coins: u64, asset_id: b256, burn_amount: u64); | ||
} |
9 changes: 9 additions & 0 deletions
9
test/src/e2e_vm_tests/test_programs/test_fuel_coin_contract/Forc.toml
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,9 @@ | ||
[project] | ||
author = "Fuel Labs <[email protected]>" | ||
license = "Apache-2.0" | ||
name = "test_fuel_coin_contract" | ||
entry = "main.sw" | ||
|
||
[dependencies] | ||
std = { git = "http://github.com/FuelLabs/sway-lib-std", version = "v0.0.1" } | ||
test_fuel_coin_abi = { path = "../test_fuel_coin_abi" } |
1 change: 1 addition & 0 deletions
1
test/src/e2e_vm_tests/test_programs/test_fuel_coin_contract/json_abi_oracle.json
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 @@ | ||
[{"inputs":[{"components":null,"name":"gas","type":"u64"},{"components":null,"name":"coins","type":"u64"},{"components":null,"name":"asset_id","type":"b256"},{"components":null,"name":"mint_amount","type":"u64"}],"name":"mint","outputs":[{"components":null,"name":"","type":"()"}],"type":"function"},{"inputs":[{"components":null,"name":"gas","type":"u64"},{"components":null,"name":"coins","type":"u64"},{"components":null,"name":"asset_id","type":"b256"},{"components":null,"name":"burn_amount","type":"u64"}],"name":"burn","outputs":[{"components":null,"name":"","type":"()"}],"type":"function"},{"inputs":[{"components":null,"name":"gas","type":"u64"},{"components":null,"name":"coins","type":"u64"},{"components":null,"name":"asset_id","type":"b256"},{"components":[{"components":null,"name":"coins","type":"u64"},{"components":[{"components":null,"name":"value","type":"b256"}],"name":"asset_id","type":"struct ContractId"},{"components":[{"components":null,"name":"value","type":"b256"}],"name":"recipient","type":"struct Address"}],"name":"params","type":"struct ParamsTransferToOutput"}],"name":"transfer_to_output","outputs":[{"components":null,"name":"","type":"()"}],"type":"function"},{"inputs":[{"components":null,"name":"gas","type":"u64"},{"components":null,"name":"coins","type":"u64"},{"components":null,"name":"asset_id","type":"b256"},{"components":[{"components":null,"name":"coins","type":"u64"},{"components":[{"components":null,"name":"value","type":"b256"}],"name":"asset_id","type":"struct ContractId"},{"components":[{"components":null,"name":"value","type":"b256"}],"name":"c_id","type":"struct ContractId"}],"name":"params","type":"struct ParamsForceTransfer"}],"name":"force_transfer","outputs":[{"components":null,"name":"","type":"()"}],"type":"function"},{"inputs":[{"components":null,"name":"gas","type":"u64"},{"components":null,"name":"coins","type":"u64"},{"components":null,"name":"asset_id","type":"b256"},{"components":null,"name":"input","type":"()"}],"name":"name","outputs":[{"components":null,"name":"","type":"str[14]"}],"type":"function"}] |
16 changes: 16 additions & 0 deletions
16
test/src/e2e_vm_tests/test_programs/test_fuel_coin_contract/src/main.sw
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,16 @@ | ||
contract; | ||
|
||
use std::token::*; | ||
use test_fuel_coin_abi::*; | ||
|
||
impl TestFuelCoin for Contract { | ||
|
||
// TODO add event logging | ||
fn mint(gas: u64, coins: u64, asset_id: b256, mint_amount: u64) { | ||
mint(coins); | ||
} | ||
|
||
fn burn(gas: u64, coins: u64, asset_id: b256, burn_amount: u64) { | ||
burn(coins); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
test/src/e2e_vm_tests/test_programs/token_ops_test/Forc.toml
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,11 @@ | ||
[project] | ||
author = "Fuel Labs <[email protected]>" | ||
license = "Apache-2.0" | ||
name = "token_ops_test" | ||
entry = "main.sw" | ||
|
||
[dependencies] | ||
std = { git = "http://github.com/FuelLabs/sway-lib-std", version = "v0.0.1" } | ||
core = { git = "http://github.com/FuelLabs/sway-lib-core", version = "v0.0.1" } | ||
test_fuel_coin_abi = { path = "../test_fuel_coin_abi" } | ||
|
46 changes: 46 additions & 0 deletions
46
test/src/e2e_vm_tests/test_programs/token_ops_test/src/main.sw
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,46 @@ | ||
script; | ||
|
||
// use std::constants::ETH_ID; | ||
use std::context::balance_of_contract; | ||
use std::chain::assert; | ||
use std::address::Address; | ||
use std::contract_id::ContractId; | ||
use std::token::*; | ||
use test_fuel_coin_abi::*; | ||
|
||
struct Opts { | ||
gas: u64, | ||
coins: u64, | ||
id: ContractId, | ||
} | ||
|
||
fn main() -> bool { | ||
|
||
let default = Opts { | ||
gas: 1_000_000_000_000, | ||
coins: 0, | ||
id: ~ContractId::from(0x0000000000000000000000000000000000000000000000000000000000000000), | ||
}; | ||
|
||
// the deployed fuel_coin Contract_Id: | ||
let fuelcoin_id = ~ContractId::from(0x49050d88db785fdf3b3fd35df44fbe644b9b5273ae97d9c7c19cc3e4aa361eaf); | ||
// todo: use correct type ContractId | ||
let fuel_coin = abi(TestFuelCoin, 0x49050d88db785fdf3b3fd35df44fbe644b9b5273ae97d9c7c19cc3e4aa361eaf); | ||
|
||
let mut fuelcoin_balance = balance_of_contract(fuelcoin_id.value, fuelcoin_id); | ||
assert(fuelcoin_balance == 0); | ||
|
||
fuel_coin.mint(default.gas, default.coins, default.id.value, 11); | ||
|
||
// check that the mint was successful | ||
fuelcoin_balance = balance_of_contract(fuelcoin_id.value, fuelcoin_id); | ||
assert(fuelcoin_balance == 11); | ||
|
||
fuel_coin.burn(default.gas, default.coins, default.id.value, 7); | ||
|
||
// check that the burn was successful | ||
fuelcoin_balance = balance_of_contract(fuelcoin_id.value, fuelcoin_id); | ||
assert(fuelcoin_balance == 4); | ||
|
||
true | ||
} |