Skip to content

Commit

Permalink
changed extra type optional; updated examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jakehemmerle committed Oct 31, 2023
1 parent 416b784 commit 0e20cdc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
6 changes: 4 additions & 2 deletions examples/barebones/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ mod tests {
#[test]
fn test_should_sign() {
let signature_request = InitialState {
data: "some_data_longer_than_10_bytes".to_string().into_bytes(),
preimage: "some_data_longer_than_10_bytes".to_string().into_bytes(),
extra: None
};

assert!(BarebonesProgram::evaluate(signature_request).is_ok());
Expand All @@ -50,7 +51,8 @@ mod tests {
fn test_should_error() {
// data being checked is under 10 bytes in length
let signature_request = InitialState {
data: "under10".to_string().into_bytes(),
preimage: "under10".to_string().into_bytes(),
extra: None
};

assert!(BarebonesProgram::evaluate(signature_request).is_err());
Expand Down
6 changes: 4 additions & 2 deletions examples/basic-transaction/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ mod tests {
fn test_evaluate() {
let signature_request = InitialState {
// `data` is an RLP serialized ETH transaction with the recipient set to `0x772b9a9e8aa1c9db861c6611a82d251db4fac990`
data: "0xef01808094772b9a9e8aa1c9db861c6611a82d251db4fac990019243726561746564204f6e20456e74726f7079018080".to_string().into_bytes(),
preimage: "0xef01808094772b9a9e8aa1c9db861c6611a82d251db4fac990019243726561746564204f6e20456e74726f7079018080".to_string().into_bytes(),
extra: None
};

assert!(BasicTransaction::evaluate(signature_request).is_ok());
Expand All @@ -64,7 +65,8 @@ mod tests {
fn test_start_fail() {
let signature_request = InitialState {
// `data` is the same as previous test, but recipient address ends in `1` instead of `0`, so it should fail
data: "0xef01808094772b9a9e8aa1c9db861c6611a82d251db4fac991019243726561746564204f6e20456e74726f7079018080".to_string().into_bytes(),
preimage: "0xef01808094772b9a9e8aa1c9db861c6611a82d251db4fac991019243726561746564204f6e20456e74726f7079018080".to_string().into_bytes(),
extra: None
};

assert!(BasicTransaction::evaluate(signature_request).is_err());
Expand Down
11 changes: 8 additions & 3 deletions examples/siwe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ export_program!(Siwe);
// write a test that calls evaluate and passes it the proper parameters
#[cfg(test)]
mod tests {
use alloc::vec;

use super::*;

#[test]
fn test_should_sign() {
let signature_request = InitialState {
data: "localhost wants you to sign in with your Ethereum account:
preimage: "localhost wants you to sign in with your Ethereum account:
0x6Ee9894c677EFa1c56392e5E7533DE76004C8D94
This is a test statement.
Expand All @@ -60,6 +62,7 @@ Nonce: oNCEHm5jzQU2WvuBB
Issued At: 2022-01-28T23:28:16.013Z"
.to_string()
.into_bytes(),
extra: None
};

assert!(Siwe::evaluate(signature_request).is_ok());
Expand All @@ -68,7 +71,7 @@ Issued At: 2022-01-28T23:28:16.013Z"
#[test]
fn test_bad_siwe_message() {
let signature_request = InitialState {
data: "localhost does not want you to sign in with your Ethereum account:
preimage: "localhost does not want you to sign in with your Ethereum account:
0x6Ee9894c677EFa1c56392e5E7533DE76004C8D94
This is a test statement.
Expand All @@ -80,6 +83,7 @@ Nonce: oNCEHm5jzQU2WvuBB
Issued At: 2022-01-28T23:28:16.013Z"
.to_string()
.into_bytes(),
extra: None
};

assert!(Siwe::evaluate(signature_request).is_err());
Expand All @@ -88,7 +92,7 @@ Issued At: 2022-01-28T23:28:16.013Z"
#[test]
fn test_bad_domain() {
let signature_request = InitialState {
data: "google.com does not want you to sign in with your Ethereum account:
preimage: "google.com does not want you to sign in with your Ethereum account:
0x6Ee9894c677EFa1c56392e5E7533DE76004C8D94
This is a test statement.
Expand All @@ -100,6 +104,7 @@ Nonce: oNCEHm5jzQU2WvuBB
Issued At: 2022-01-28T23:28:16.013Z"
.to_string()
.into_bytes(),
extra: None
};

assert!(Siwe::evaluate(signature_request).is_err());
Expand Down
2 changes: 1 addition & 1 deletion wit/application.wit
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ world program {
/// Preimage of the user's data under program evaulation (eg. RLP-encoded ETH transaction request).
preimage: list<u8>,
/// Auxiliary data required for program evaluation, that won't be signed (eg. zero-knowledge proof, third party signature)
extra: list<u8>
extra: option<list<u8>>
}
}

0 comments on commit 0e20cdc

Please sign in to comment.