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

Added Checks for the Length of Arguments List #533

Merged
merged 23 commits into from
Oct 28, 2024
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9ca3149
feat: added checks for the length of arguments list
BowTiedWoo Oct 14, 2024
43ecb90
feat: add error variant for invalid argument length
BowTiedWoo Oct 14, 2024
117e02b
feat: add tests for length of args list
BowTiedWoo Oct 14, 2024
2cdaa75
Merge branch 'main' into feat/check-args-length
BowTiedWoo Oct 15, 2024
4c8655d
feat: add runtime error for arg length and update tests
BowTiedWoo Oct 18, 2024
c0e0fef
Merge branch 'main' into feat/check-args-length
BowTiedWoo Oct 18, 2024
552f79f
feat: modify arg checks and arg count errors
BowTiedWoo Oct 18, 2024
4866a0e
fix: remove code duplications
BowTiedWoo Oct 18, 2024
3f893c1
fix: add functions for checking arg length
BowTiedWoo Oct 18, 2024
fe2af84
fix: refactor to remove code duplication
BowTiedWoo Oct 21, 2024
db6ae8f
fix: update tests
BowTiedWoo Oct 21, 2024
ea22f47
Merge branch 'main' into feat/check-args-length
BowTiedWoo Oct 21, 2024
40dacf7
chore: remove prints
BowTiedWoo Oct 22, 2024
a1c8206
chore: add comments on tests where typechecker fails
BowTiedWoo Oct 22, 2024
01bd418
Merge branch 'main' into feat/check-args-length
BowTiedWoo Oct 22, 2024
8be2284
Merge branch 'main' into feat/check-args-length
BowTiedWoo Oct 22, 2024
e0c678e
fix: update tests to use crosscheck
BowTiedWoo Oct 22, 2024
6bf5b05
fix: format code
BowTiedWoo Oct 23, 2024
90bfb36
fix: remove prints
BowTiedWoo Oct 23, 2024
b415867
feat: short-cut traverse function
BowTiedWoo Oct 23, 2024
5c2afe2
feat: add arg count check for user defined fns
BowTiedWoo Oct 24, 2024
e8936cc
Merge branch 'main' into feat/check-args-length
BowTiedWoo Oct 24, 2024
341ec46
feat: read/write arg lengths from/to memory as bytes
BowTiedWoo Oct 25, 2024
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
Prev Previous commit
Next Next commit
Merge branch 'main' into feat/check-args-length
  • Loading branch information
BowTiedWoo authored Oct 18, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit c0e0fef3346fcf567a96ebceb03868ff4f5f7047
40 changes: 37 additions & 3 deletions clar2wasm/src/error_mapping.rs
Original file line number Diff line number Diff line change
@@ -56,9 +56,21 @@ pub enum ErrorMap {

/// Indicates an attempt to use a name that is already in use, possibly for a variable or function.
NameAlreadyUsed = 9,

/// Represents a short-return error for an expected value that wraps a Response type.
/// Usually triggered by `(try!...)`.
ShortReturnExpectedValueResponse = 10,

/// Indicates an attempt to use a function with the wrong amount of arguments
ArgumentCountMismatch = 10,
/// Represents a short-return error for an expected value that wraps an Optional type.
/// Usually triggered by `(try!...)`.
ShortReturnExpectedValueOptional = 11,

/// Represents a short-return error for an expected value.
/// usually triggered by `(unwrap!...)` and `(unwrap-err!...)`.
ShortReturnExpectedValue = 12,

/// Indicates an attempt to use a function with the wrong amount of arguments
ArgumentCountMismatch = 13,

/// A catch-all for errors that are not mapped to specific error codes.
/// This might be used for unexpected or unclassified errors.
@@ -79,7 +91,10 @@ impl From<i32> for ErrorMap {
7 => ErrorMap::ShortReturnAssertionFailure,
8 => ErrorMap::ArithmeticPowError,
9 => ErrorMap::NameAlreadyUsed,
10 => ErrorMap::ArgumentCountMismatch,
10 => ErrorMap::ShortReturnExpectedValueResponse,
11 => ErrorMap::ShortReturnExpectedValueOptional,
12 => ErrorMap::ShortReturnExpectedValue,
13 => ErrorMap::ArgumentCountMismatch,
_ => ErrorMap::NotMapped,
}
}
@@ -229,6 +244,25 @@ fn from_runtime_error_code(

Error::Unchecked(CheckErrors::NameAlreadyUsed(arg_name))
}
ErrorMap::ShortReturnExpectedValueResponse => {
let clarity_val = short_return_value(&instance, &mut store, epoch_id, clarity_version);
Error::ShortReturn(ShortReturnType::ExpectedValue(Value::Response(
ResponseData {
committed: false,
data: Box::new(clarity_val),
},
)))
}
ErrorMap::ShortReturnExpectedValueOptional => {
Error::ShortReturn(ShortReturnType::ExpectedValue(Value::Optional(
clarity::vm::types::OptionalData { data: None },
)))
}
ErrorMap::ShortReturnExpectedValue => {
let clarity_val = short_return_value(&instance, &mut store, epoch_id, clarity_version);
Error::ShortReturn(ShortReturnType::ExpectedValue(clarity_val))

}
ErrorMap::ArgumentCountMismatch => {
let runtime_error_arg_offset = instance
.get_global(&mut store, "runtime-error-arg-offset")
21 changes: 21 additions & 0 deletions clar2wasm/src/words/conditionals.rs
Original file line number Diff line number Diff line change
@@ -1465,5 +1465,26 @@ mod tests {
.unwrap_err()
.to_string()
.contains("expecting 2 arguments, got 3"));
}
fn try_response_false() {
crosscheck(
"(try! (if false (ok u1) (err u42)))",
Err(Error::ShortReturn(ShortReturnType::ExpectedValue(
Value::Response(ResponseData {
committed: false,
data: Box::new(Value::UInt(42)),
}),
))),
)
}

#[test]
fn try_optional_false() {
crosscheck(
"(try! (if false (some u1) none))",
Err(Error::ShortReturn(ShortReturnType::ExpectedValue(
Value::Optional(clarity::vm::types::OptionalData { data: None }),
))),
)
}
}
3 changes: 3 additions & 0 deletions clar2wasm/src/words/tokens.rs
Original file line number Diff line number Diff line change
@@ -579,6 +579,9 @@ impl ComplexWord for GetOwnerOfNonFungibleToken {
mod tests {
use crate::tools::{crosscheck, crosscheck_expect_failure, evaluate};

use clarity::vm::types::{PrincipalData, TupleData};
use clarity::vm::Value;

//
// Module with tests that should only be executed
// when running Clarity::V1.
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.