From a2d06538a0b5e79a1a21b0d4555ff0fda5034166 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Wed, 1 May 2024 11:26:47 +0200 Subject: [PATCH] Add regression tests for issue #407 --- crates/edr_provider/tests/issue_407.rs | 139 +++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 crates/edr_provider/tests/issue_407.rs diff --git a/crates/edr_provider/tests/issue_407.rs b/crates/edr_provider/tests/issue_407.rs new file mode 100644 index 000000000..909b15815 --- /dev/null +++ b/crates/edr_provider/tests/issue_407.rs @@ -0,0 +1,139 @@ +#![cfg(feature = "test-utils")] + +use edr_provider::{test_utils::create_test_config, time::CurrentTime, NoopLogger, Provider}; +use serde_json::json; +use tokio::runtime; + +// https://github.com/NomicFoundation/edr/issues/407 + +#[tokio::test(flavor = "multi_thread")] +async fn issue_407_uint() -> anyhow::Result<()> { + let config = create_test_config(); + let logger = Box::new(NoopLogger); + let subscriber = Box::new(|_event| {}); + let provider = Provider::new( + runtime::Handle::current(), + logger, + subscriber, + config, + CurrentTime, + )?; + + let request_with_uint = json!({ + "method": "eth_signTypedData_v4", + "params": [ + "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266", + { + "types": { + "Test": [ + { + "name": "amount", + "type": "uint256" + } + ], + "EIP712Domain": [ + { + "name": "name", + "type": "string" + }, + { + "name": "version", + "type": "string" + }, + { + "name": "chainId", + "type": "uint256" + }, + { + "name": "verifyingContract", + "type": "address" + } + ] + }, + "domain": { + "name": "TestName", + "version": "1", + "chainId": "0x7a69", + "verifyingContract": "0x1111111111111111111111111111111111111111" + }, + "primaryType": "Test", + "message": { + "amount": "1234" + } + } + ] + }); + + let response = provider + .handle_request(serde_json::from_value(request_with_uint)?)?; + + assert_eq!(response.result, "0x2d9b08a9086931cc3ebb9ae446d440e43f0e4ca0abedd2d973af8278c5471bb54181a8dae6018d14d29d62facc535fbba5b4010cdb3f06c0ddcf72e2663583361b"); + + Ok(()) +} + +#[tokio::test(flavor = "multi_thread")] +async fn issue_407_int() -> anyhow::Result<()> { + let config = create_test_config(); + let logger = Box::new(NoopLogger); + let subscriber = Box::new(|_event| {}); + let provider = Provider::new( + runtime::Handle::current(), + logger, + subscriber, + config, + CurrentTime, + )?; + + let request_with_uint = json!({ + "method": "eth_signTypedData_v4", + "params": [ + "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266", + { + "types": { + "Test": [ + { + "name": "amount", + "type": "int256" + } + ], + "EIP712Domain": [ + { + "name": "name", + "type": "string" + }, + { + "name": "version", + "type": "string" + }, + { + "name": "chainId", + "type": "uint256" + }, + { + "name": "verifyingContract", + "type": "address" + } + ] + }, + "domain": { + "name": "TestName", + "version": "1", + "chainId": "0x7a69", + "verifyingContract": "0x1111111111111111111111111111111111111111" + }, + "primaryType": "Test", + "message": { + "amount": "1234" + } + } + ] + }); + + let response = provider + .handle_request(serde_json::from_value(request_with_uint)?)?; + + assert_eq!(response.result, "0x30622c2e4318a3ffb2755ca111f42409bd5a4190b4b8a9b5f42227313708ecb54889d229dfb7dcfb246f15e7567ef7471fb26a7e99d83631d266a144502ee29f1c"); + + Ok(()) +} \ No newline at end of file