Skip to content

Commit

Permalink
[test] Add a signature test for verify message signature from starcoi…
Browse files Browse the repository at this point in the history
…n cli. (#17)
  • Loading branch information
jolestar committed Apr 6, 2022
1 parent 60c8002 commit f88c277
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
12 changes: 10 additions & 2 deletions spectests/natives/signature.exp
@@ -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
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

0 comments on commit f88c277

Please sign in to comment.