-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rpc): v.0.8 only allows v3 transactions in the write api
- Loading branch information
Showing
8 changed files
with
354 additions
and
3 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
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
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,7 @@ | ||
mod add_declare_transaction; | ||
mod add_deploy_account_transaction; | ||
mod add_invoke_transaction; | ||
|
||
pub use add_declare_transaction::add_declare_transaction; | ||
pub use add_deploy_account_transaction::add_deploy_account_transaction; | ||
pub use add_invoke_transaction::add_invoke_transaction; |
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,37 @@ | ||
use crate::context::RpcContext; | ||
use crate::method::add_declare_transaction::{AddDeclareTransactionError, Input, Output}; | ||
|
||
pub async fn add_declare_transaction( | ||
context: RpcContext, | ||
input: Input, | ||
) -> Result<Output, AddDeclareTransactionError> { | ||
if !input.is_v3_transaction() { | ||
return Err(AddDeclareTransactionError::UnsupportedTransactionVersion); | ||
} | ||
|
||
crate::method::add_declare_transaction::add_declare_transaction(context, input).await | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::context::RpcContext; | ||
|
||
#[rstest::rstest] | ||
#[case::v0_is_unsupported(Input::for_test_with_v0_transaction(), false)] | ||
#[case::v1_is_unsupported(Input::for_test_with_v1_transaction(), false)] | ||
#[case::v2_is_unsupported(Input::for_test_with_v2_transaction(), false)] | ||
#[case::v3_is_supported(Input::for_test_with_v3_transaction(), true)] | ||
#[tokio::test] | ||
async fn only_v3_transactions_are_accepted(#[case] input: Input, #[case] is_supported: bool) { | ||
let context = RpcContext::for_tests(); | ||
let result = add_declare_transaction(context, input).await; | ||
assert_eq!( | ||
!is_supported, | ||
matches!( | ||
result, | ||
Err(AddDeclareTransactionError::UnsupportedTransactionVersion) | ||
) | ||
); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
crates/rpc/src/v08/method/add_deploy_account_transaction.rs
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,40 @@ | ||
use crate::context::RpcContext; | ||
use crate::method::add_deploy_account_transaction::{ | ||
AddDeployAccountTransactionError, | ||
Input, | ||
Output, | ||
}; | ||
|
||
pub async fn add_deploy_account_transaction( | ||
context: RpcContext, | ||
input: Input, | ||
) -> Result<Output, AddDeployAccountTransactionError> { | ||
if !input.is_v3_transaction() { | ||
return Err(AddDeployAccountTransactionError::UnsupportedTransactionVersion); | ||
} | ||
|
||
crate::method::add_deploy_account_transaction::add_deploy_account_transaction(context, input) | ||
.await | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::context::RpcContext; | ||
|
||
#[rstest::rstest] | ||
#[case::v1_is_unsupported(Input::for_test_with_v1_transaction(), false)] | ||
#[case::v3_is_supported(Input::for_test_with_v3_transaction(), true)] | ||
#[tokio::test] | ||
async fn only_v3_transactions_are_accepted(#[case] input: Input, #[case] is_supported: bool) { | ||
let context = RpcContext::for_tests(); | ||
let result = add_deploy_account_transaction(context, input).await; | ||
assert_eq!( | ||
!is_supported, | ||
matches!( | ||
result, | ||
Err(AddDeployAccountTransactionError::UnsupportedTransactionVersion) | ||
) | ||
); | ||
} | ||
} |
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,36 @@ | ||
use crate::context::RpcContext; | ||
use crate::method::add_invoke_transaction::{AddInvokeTransactionError, Input, Output}; | ||
|
||
pub async fn add_invoke_transaction( | ||
context: RpcContext, | ||
input: Input, | ||
) -> Result<Output, AddInvokeTransactionError> { | ||
if !input.is_v3_transaction() { | ||
return Err(AddInvokeTransactionError::UnsupportedTransactionVersion); | ||
} | ||
|
||
crate::method::add_invoke_transaction::add_invoke_transaction(context, input).await | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::context::RpcContext; | ||
|
||
#[rstest::rstest] | ||
#[case::v0_is_unsupported(Input::for_test_with_v0_transaction(), false)] | ||
#[case::v1_is_unsupported(Input::for_test_with_v1_transaction(), false)] | ||
#[case::v3_is_supported(Input::for_test_with_v3_transaction(), true)] | ||
#[tokio::test] | ||
async fn only_v3_transactions_are_accepted(#[case] input: Input, #[case] is_supported: bool) { | ||
let context = RpcContext::for_tests(); | ||
let result = add_invoke_transaction(context, input).await; | ||
assert_eq!( | ||
!is_supported, | ||
matches!( | ||
result, | ||
Err(AddInvokeTransactionError::UnsupportedTransactionVersion) | ||
) | ||
); | ||
} | ||
} |