-
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.
Add actions to install CLI and run move tests
- Loading branch information
Showing
9 changed files
with
840 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.aptos/ | ||
build/ |
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 @@ | ||
[package] | ||
name = "testing" | ||
version = "1.0.0" | ||
authors = [] | ||
|
||
[addresses] | ||
addr = "_" | ||
|
||
[dev-addresses] | ||
|
||
[dependencies.AptosFramework] | ||
git = "https://github.com/aptos-labs/aptos-framework.git" | ||
rev = "mainnet" | ||
subdir = "aptos-framework" | ||
|
||
[dev-dependencies] |
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,68 @@ | ||
module addr::message { | ||
use std::error; | ||
use std::signer; | ||
use std::string; | ||
use aptos_framework::event; | ||
#[test_only] | ||
use std::debug; | ||
|
||
//:!:>resource | ||
struct MessageHolder has key { | ||
message: string::String | ||
} | ||
|
||
//<:!:resource | ||
|
||
#[event] | ||
struct MessageChange has drop, store { | ||
account: address, | ||
from_message: string::String, | ||
to_message: string::String | ||
} | ||
|
||
/// There is no message present | ||
const ENO_MESSAGE: u64 = 0; | ||
|
||
#[view] | ||
public fun get_message(addr: address): string::String acquires MessageHolder { | ||
assert!( | ||
exists<MessageHolder>(addr), | ||
error::not_found(ENO_MESSAGE) | ||
); | ||
borrow_global<MessageHolder>(addr).message | ||
} | ||
|
||
public entry fun set_message(account: signer, message: string::String) acquires MessageHolder { | ||
let account_addr = signer::address_of(&account); | ||
if (!exists<MessageHolder>(account_addr)) { | ||
move_to(&account, MessageHolder { message }) | ||
} else { | ||
let old_message_holder = borrow_global_mut<MessageHolder>(account_addr); | ||
let from_message = old_message_holder.message; | ||
event::emit( | ||
MessageChange { | ||
account: account_addr, | ||
from_message, | ||
to_message: copy message | ||
} | ||
); | ||
old_message_holder.message = message; | ||
} | ||
} | ||
|
||
#[test(account = @0x1)] | ||
public entry fun sender_can_set_message(account: signer) acquires MessageHolder { | ||
let msg: string::String = | ||
string::utf8(b"Running test for sender_can_set_message..."); | ||
debug::print(&msg); | ||
|
||
let addr = signer::address_of(&account); | ||
aptos_framework::account::create_account_for_test(addr); | ||
set_message(account, string::utf8(b"Hello, Blockchain")); | ||
|
||
assert!( | ||
get_message(addr) == string::utf8(b"Hello, Blockchain"), | ||
ENO_MESSAGE | ||
); | ||
} | ||
} |
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
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,18 @@ | ||
## Description | ||
|
||
Install the Aptos CLI. By default we use the latest released version of the Aptos CLI but you can specify the version. For now this only works on Linux runners. | ||
|
||
## Inputs | ||
|
||
| parameter | description | required | default | | ||
| --- | --- | --- | --- | | ||
| INSTALL_DIRECTORY | The directory to install the Aptos CLI. If not specified, it will be installed in /usr/local/bin | `false` | /usr/local/bin | | ||
| CLI_VERSION | The version of the Aptos CLI to install. If not specified, the latest version will be installed. | `false` | | | ||
| SHELL | The shell to use for the steps. | `false` | bash | | ||
|
||
|
||
## Runs | ||
|
||
This action is a `composite` action. | ||
|
||
|
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,31 @@ | ||
name: Install Aptos CLI | ||
description: Install the Aptos CLI. By default we use the latest released version of the Aptos CLI but you can specify the version. For now this only works on Linux runners. | ||
|
||
inputs: | ||
INSTALL_DIRECTORY: | ||
description: "The directory to install the Aptos CLI. If not specified, it will be installed in /usr/local/bin" | ||
required: false | ||
default: "/usr/local/bin" | ||
CLI_VERSION: | ||
description: "The version of the Aptos CLI to install. If not specified, the latest version will be installed." | ||
required: false | ||
SHELL: | ||
description: "The shell to use for the steps." | ||
required: false | ||
default: "bash" | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: Fetch installation script | ||
shell: ${{ inputs.SHELL }} | ||
run: curl -fSL "https://aptos.dev/scripts/install_cli.py" -o ${{ runner.temp }}/install_cli.py | ||
|
||
- name: Install Aptos CLI | ||
shell: ${{ inputs.SHELL }} | ||
run: | | ||
if [ -n "${{ inputs.CLI_VERSION }}" ]; then | ||
python3 ${{ runner.temp }}/install_cli.py -f -y --bin-dir ${{ inputs.INSTALL_DIRECTORY }} --cli-version ${{ inputs.CLI_VERSION }} | ||
else | ||
python3 ${{ runner.temp }}/install_cli.py -f -y --bin-dir ${{ inputs.INSTALL_DIRECTORY }} | ||
fi |
Oops, something went wrong.