Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] Add a signature test for verify message signature from starcoin cli. #17

Merged
merged 1 commit into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions spectests/natives/signature.exp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
processed 4 tasks
processed 5 tasks

task 2 'run'. lines 5-25:
{
Expand All @@ -8,7 +8,15 @@ task 2 'run'. lines 5-25:
}
}

task 3 'run'. lines 27-62:
task 3 'run'. lines 28-50:
{
"gas_used": 33522,
"status": {
"Keep": "Executed"
}
}

task 4 'run'. lines 52-87:
{
"gas_used": 170726,
"status": {
Expand Down
25 changes: 25 additions & 0 deletions spectests/natives/signature.move
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,31 @@ fun main() {
}
}


//# run --signers creator
// Test fot signature verify
// use command `starcoin account sign-message --message abc` to generate signature.
script {
use StarcoinFramework::Signature;
use StarcoinFramework::Hash;
use StarcoinFramework::Vector;
use StarcoinFramework::BCS;

fun main() {

let public_key = x"a7c56b0c7111a7068cbd5f8c841a3d01eed480cfc14806e43e7a1da71e2945f0";
let message = b"abc";
let signature = x"c46ad802f389f7e17631b28668e51565fa59b80c34b44719791c4f541b586239896fd470d64c6eff1bdfadab9861e193042dbafd8f23fda670530cce4f199f0d";
let prefix = b"STARCOIN::";
Vector::append(&mut prefix, b"SigningMessage");
let prefix_hash = Hash::sha3_256(prefix);
let data = copy prefix_hash;
Vector::append(&mut data, BCS::to_bytes(&message));
assert!(Signature::ed25519_verify(signature, public_key, data), 9004);
}

}

//# run --signers creator

// test ecrecover
Expand Down