2929import org .web3j .crypto .Keys ;
3030import org .web3j .protocol .core .methods .response .TransactionReceipt ;
3131import org .web3j .protocol .exceptions .TransactionException ;
32- import org .web3j .tx .RawTransactionManager ;
3332import org .web3j .tx .response .PollingTransactionReceiptProcessor ;
3433
3534import java .io .IOException ;
3635import java .math .BigInteger ;
3736import java .time .Duration ;
3837import java .time .Instant ;
38+ import java .util .Map ;
3939import java .util .Optional ;
4040
4141import static org .assertj .core .api .Assertions .assertThatThrownBy ;
@@ -59,8 +59,6 @@ class IexecHubServiceTests {
5959 @ Mock
6060 private PollingTransactionReceiptProcessor txReceiptProcessor ;
6161 @ Mock
62- private RawTransactionManager txManager ;
63- @ Mock
6462 private Web3jService web3jService ;
6563 @ Mock
6664 private TransactionReceipt receipt ;
@@ -72,7 +70,6 @@ void init() {
7270 when (signerService .getCredentials ()).thenReturn (credentials );
7371 iexecHubService = spy (new IexecHubService (signerService , web3jService , chainConfig ));
7472 ReflectionTestUtils .setField (iexecHubService , "txReceiptProcessor" , txReceiptProcessor );
75- ReflectionTestUtils .setField (iexecHubService , "txManager" , txManager );
7673 }
7774
7875 @ SneakyThrows
@@ -130,15 +127,15 @@ void shouldNotReveal() throws IOException {
130127 @ Test
131128 void shouldFinalizeTask () throws IOException , TransactionException {
132129 mockTransaction ();
133- when (txManager .sendCall (any (), any (), any ())).thenReturn ("0x30D40" ); // hexadecimal value for 200_000
130+ when (web3jService .sendCall (any (), any (), any ())).thenReturn ("0x30D40" ); // hexadecimal value for 200_000
134131 assertThat (iexecHubService .finalizeTask (chainTaskId , "resultLink" , "callbackData" ))
135132 .isEqualTo (receipt );
136133 }
137134
138135 @ Test
139136 void shouldNotFinalizeTask () throws IOException {
140137 when (signerService .estimateGas (any (), any ())).thenReturn (BigInteger .valueOf (100_000L ));
141- when (txManager .sendCall (any (), any (), any ())).thenReturn ("0x30D40" ); // hexadecimal value for 200_000
138+ when (web3jService .sendCall (any (), any (), any ())).thenReturn ("0x30D40" ); // hexadecimal value for 200_000
142139 when (signerService .signAndSendTransaction (any (), any (), any (), any (), any ()))
143140 .thenThrow (IOException .class );
144141 assertThatThrownBy (() -> iexecHubService .finalizeTask (chainTaskId , "resultLink" , "callbackData" ))
@@ -176,9 +173,10 @@ void shouldNotBeBeforeContributionDeadline() {
176173 @ Test
177174 void shouldBeBeforeContributionDeadline () {
178175 final BigInteger startTime = BigInteger .valueOf (Instant .now ().getEpochSecond ());
179- final ChainCategory category = ChainCategory .builder ().id (0 ).maxExecutionTime (1000L ).build ();
180- doReturn (Optional .of (ChainDeal .builder ().chainCategory (category ).startTime (startTime ).build ()))
181- .when (iexecHubService ).getChainDeal ("dealId" );
176+ final ChainCategory category = ChainCategory .builder ().maxExecutionTime (1000L ).build ();
177+ ReflectionTestUtils .setField (iexecHubService , "categories" , Map .of (0L , category ));
178+ when (iexecHubService .getChainDeal ("dealId" ))
179+ .thenReturn (Optional .of (ChainDeal .builder ().chainCategory (category ).startTime (startTime ).build ()));
182180 assertThat (iexecHubService .isBeforeContributionDeadline ("dealId" ))
183181 .isTrue ();
184182 }
0 commit comments