@@ -6,7 +6,6 @@ use crate::api::response::{
66use crate :: config:: AptosConfig ;
77use crate :: error:: { AptosError , AptosResult } ;
88use crate :: retry:: { RetryConfig , RetryExecutor } ;
9- use crate :: transaction:: simulation:: SimulateQueryOptions ;
109use crate :: transaction:: types:: SignedTransaction ;
1110use crate :: types:: { AccountAddress , HashValue } ;
1211use reqwest:: Client ;
@@ -398,32 +397,15 @@ impl FullnodeClient {
398397
399398 /// Simulates a transaction.
400399 ///
401- /// Optionally pass [`SimulateQueryOptions`] to request gas estimation behavior
402- /// (e.g. `estimate_gas_unit_price`, `estimate_max_gas_amount`) as query
403- /// parameters to the `/transactions/simulate` endpoint.
404- ///
405400 /// # Errors
406401 ///
407402 /// Returns an error if the transaction cannot be serialized to BCS, the HTTP request fails,
408403 /// the API returns an error status code, or the response cannot be parsed as JSON.
409404 pub async fn simulate_transaction (
410405 & self ,
411406 signed_txn : & SignedTransaction ,
412- options : impl Into < Option < SimulateQueryOptions > > ,
413407 ) -> AptosResult < AptosResponse < Vec < serde_json:: Value > > > {
414- let mut url = self . build_url ( "transactions/simulate" ) ;
415- if let Some ( opts) = options. into ( ) {
416- let mut pairs = url. query_pairs_mut ( ) ;
417- if opts. estimate_gas_unit_price {
418- pairs. append_pair ( "estimate_gas_unit_price" , "true" ) ;
419- }
420- if opts. estimate_max_gas_amount {
421- pairs. append_pair ( "estimate_max_gas_amount" , "true" ) ;
422- }
423- if opts. estimate_prioritized_gas_unit_price {
424- pairs. append_pair ( "estimate_prioritized_gas_unit_price" , "true" ) ;
425- }
426- }
408+ let url = self . build_url ( "transactions/simulate" ) ;
427409 let bcs_bytes = signed_txn. to_bcs ( ) ?;
428410 let client = self . client . clone ( ) ;
429411 let retry_config = self . retry_config . clone ( ) ;
@@ -859,10 +841,6 @@ impl FullnodeClient {
859841#[ cfg( test) ]
860842mod tests {
861843 use super :: * ;
862- use crate :: transaction:: simulation:: SimulateQueryOptions ;
863- use crate :: transaction:: types:: { RawTransaction , SignedTransaction } ;
864- use crate :: transaction:: authenticator:: { Ed25519PublicKey , Ed25519Signature , TransactionAuthenticator } ;
865- use crate :: types:: ChainId ;
866844 use wiremock:: {
867845 Mock , MockServer , ResponseTemplate ,
868846 matchers:: { method, path, path_regex} ,
@@ -882,45 +860,6 @@ mod tests {
882860 FullnodeClient :: new ( config) . unwrap ( )
883861 }
884862
885- /// Creates a minimal SignedTransaction for use in simulate_transaction tests.
886- fn create_minimal_signed_transaction ( ) -> SignedTransaction {
887- use crate :: transaction:: payload:: { EntryFunction , TransactionPayload } ;
888-
889- let raw = RawTransaction :: new (
890- AccountAddress :: ONE ,
891- 0 ,
892- TransactionPayload :: EntryFunction (
893- EntryFunction :: apt_transfer ( AccountAddress :: ONE , 0 ) . unwrap ( ) ,
894- ) ,
895- 100_000 ,
896- 100 ,
897- std:: time:: SystemTime :: now ( )
898- . duration_since ( std:: time:: UNIX_EPOCH )
899- . unwrap ( )
900- . as_secs ( )
901- . saturating_add ( 600 ) ,
902- ChainId :: testnet ( ) ,
903- ) ;
904- let auth = TransactionAuthenticator :: Ed25519 {
905- public_key : Ed25519PublicKey ( [ 0u8 ; 32 ] ) ,
906- signature : Ed25519Signature ( [ 0u8 ; 64 ] ) ,
907- } ;
908- SignedTransaction :: new ( raw, auth)
909- }
910-
911- fn simulate_response_json ( ) -> serde_json:: Value {
912- serde_json:: json!( [ {
913- "success" : true ,
914- "vm_status" : "Executed successfully" ,
915- "gas_used" : "100" ,
916- "max_gas_amount" : "200000" ,
917- "gas_unit_price" : "100" ,
918- "hash" : "0x1" ,
919- "changes" : [ ] ,
920- "events" : [ ]
921- } ] )
922- }
923-
924863 #[ tokio:: test]
925864 async fn test_get_ledger_info ( ) {
926865 let server = MockServer :: start ( ) . await ;
@@ -1268,149 +1207,4 @@ mod tests {
12681207
12691208 assert_eq ! ( result. data. len( ) , 1 ) ;
12701209 }
1271-
1272- #[ tokio:: test]
1273- async fn test_simulate_transaction_with_estimate_gas_unit_price ( ) {
1274- let server = MockServer :: start ( ) . await ;
1275-
1276- Mock :: given ( method ( "POST" ) )
1277- . and ( path ( "/v1/transactions/simulate" ) )
1278- . and ( |req : & wiremock:: Request | {
1279- req. url
1280- . query ( )
1281- . map_or ( false , |q| q. contains ( "estimate_gas_unit_price=true" ) )
1282- } )
1283- . respond_with (
1284- ResponseTemplate :: new ( 200 ) . set_body_json ( simulate_response_json ( ) ) ,
1285- )
1286- . expect ( 1 )
1287- . mount ( & server)
1288- . await ;
1289-
1290- let client = create_mock_client ( & server) ;
1291- let signed = create_minimal_signed_transaction ( ) ;
1292- let opts = SimulateQueryOptions :: new ( ) . estimate_gas_unit_price ( true ) ;
1293- let result = client
1294- . simulate_transaction ( & signed, Some ( opts) )
1295- . await
1296- . unwrap ( ) ;
1297- assert ! ( !result. data. is_empty( ) ) ;
1298- }
1299-
1300- #[ tokio:: test]
1301- async fn test_simulate_transaction_with_estimate_max_gas_amount ( ) {
1302- let server = MockServer :: start ( ) . await ;
1303-
1304- Mock :: given ( method ( "POST" ) )
1305- . and ( path ( "/v1/transactions/simulate" ) )
1306- . and ( |req : & wiremock:: Request | {
1307- req. url
1308- . query ( )
1309- . map_or ( false , |q| q. contains ( "estimate_max_gas_amount=true" ) )
1310- } )
1311- . respond_with (
1312- ResponseTemplate :: new ( 200 ) . set_body_json ( simulate_response_json ( ) ) ,
1313- )
1314- . expect ( 1 )
1315- . mount ( & server)
1316- . await ;
1317-
1318- let client = create_mock_client ( & server) ;
1319- let signed = create_minimal_signed_transaction ( ) ;
1320- let opts = SimulateQueryOptions :: new ( ) . estimate_max_gas_amount ( true ) ;
1321- let result = client
1322- . simulate_transaction ( & signed, Some ( opts) )
1323- . await
1324- . unwrap ( ) ;
1325- assert ! ( !result. data. is_empty( ) ) ;
1326- }
1327-
1328- #[ tokio:: test]
1329- async fn test_simulate_transaction_with_estimate_prioritized_gas_unit_price ( ) {
1330- let server = MockServer :: start ( ) . await ;
1331-
1332- Mock :: given ( method ( "POST" ) )
1333- . and ( path ( "/v1/transactions/simulate" ) )
1334- . and ( |req : & wiremock:: Request | {
1335- req. url . query ( ) . map_or ( false , |q| {
1336- q. contains ( "estimate_prioritized_gas_unit_price=true" )
1337- } )
1338- } )
1339- . respond_with (
1340- ResponseTemplate :: new ( 200 ) . set_body_json ( simulate_response_json ( ) ) ,
1341- )
1342- . expect ( 1 )
1343- . mount ( & server)
1344- . await ;
1345-
1346- let client = create_mock_client ( & server) ;
1347- let signed = create_minimal_signed_transaction ( ) ;
1348- let opts = SimulateQueryOptions :: new ( ) . estimate_prioritized_gas_unit_price ( true ) ;
1349- let result = client
1350- . simulate_transaction ( & signed, Some ( opts) )
1351- . await
1352- . unwrap ( ) ;
1353- assert ! ( !result. data. is_empty( ) ) ;
1354- }
1355-
1356- #[ tokio:: test]
1357- async fn test_simulate_transaction_with_all_options ( ) {
1358- let server = MockServer :: start ( ) . await ;
1359-
1360- Mock :: given ( method ( "POST" ) )
1361- . and ( path ( "/v1/transactions/simulate" ) )
1362- . and ( |req : & wiremock:: Request | {
1363- req. url . query ( ) . map_or ( false , |q| {
1364- q. contains ( "estimate_gas_unit_price=true" )
1365- && q. contains ( "estimate_max_gas_amount=true" )
1366- && q. contains ( "estimate_prioritized_gas_unit_price=true" )
1367- } )
1368- } )
1369- . respond_with (
1370- ResponseTemplate :: new ( 200 ) . set_body_json ( simulate_response_json ( ) ) ,
1371- )
1372- . expect ( 1 )
1373- . mount ( & server)
1374- . await ;
1375-
1376- let client = create_mock_client ( & server) ;
1377- let signed = create_minimal_signed_transaction ( ) ;
1378- let opts = SimulateQueryOptions :: new ( )
1379- . estimate_gas_unit_price ( true )
1380- . estimate_max_gas_amount ( true )
1381- . estimate_prioritized_gas_unit_price ( true ) ;
1382- let result = client
1383- . simulate_transaction ( & signed, Some ( opts) )
1384- . await
1385- . unwrap ( ) ;
1386- assert ! ( !result. data. is_empty( ) ) ;
1387- }
1388-
1389- #[ tokio:: test]
1390- async fn test_simulate_transaction_without_options ( ) {
1391- let server = MockServer :: start ( ) . await ;
1392-
1393- // Mock must NOT match if query contains any of the simulate options (so we use path only and expect no query param)
1394- Mock :: given ( method ( "POST" ) )
1395- . and ( path ( "/v1/transactions/simulate" ) )
1396- . and ( |req : & wiremock:: Request | {
1397- // URL must not contain the simulate query params when options is None
1398- req. url . query ( ) . map_or ( true , |q| {
1399- !q. contains ( "estimate_gas_unit_price=" )
1400- && !q. contains ( "estimate_max_gas_amount=" )
1401- && !q. contains ( "estimate_prioritized_gas_unit_price=" )
1402- } )
1403- } )
1404- . respond_with (
1405- ResponseTemplate :: new ( 200 ) . set_body_json ( simulate_response_json ( ) ) ,
1406- )
1407- . expect ( 1 )
1408- . mount ( & server)
1409- . await ;
1410-
1411- let client = create_mock_client ( & server) ;
1412- let signed = create_minimal_signed_transaction ( ) ;
1413- let result = client. simulate_transaction ( & signed, None ) . await . unwrap ( ) ;
1414- assert ! ( !result. data. is_empty( ) ) ;
1415- }
14161210}
0 commit comments