1515import java .util .Base64 ;
1616import java .util .Optional ;
1717
18+ import static com .iexec .commons .poco .chain .ChainContributionStatus .CONTRIBUTED ;
1819import static com .iexec .commons .poco .chain .ChainContributionStatus .REVEALED ;
1920import static org .assertj .core .api .Assertions .assertThat ;
2021import static org .mockito .Mockito .*;
2122
2223class ProxyServiceTest {
2324 private static final String CHAIN_TASK_ID = "0x59d9b6c36d6db89bae058ff55de6e4d6a6f6e0da3f9ea02297fc8d6d5f5cedf1" ;
25+ private static final String RESULT_HASH = "0x865e1ebff87de7928040a42383b46690a12a988b278eb880e0e641f5da3cc9d1" ;
2426 private static final String WALLET_ADDRESS = "0x123abc" ;
2527 /**
2628 * Contains a valid result zip, with the following files:
@@ -36,7 +38,8 @@ class ProxyServiceTest {
3638 * including a fixed ChainTask ID: {@literal 0x59d9b6c36d6db89bae058ff55de6e4d6a6f6e0da3f9ea02297fc8d6d5f5cedf1}.
3739 */
3840 private static final ChainContribution CHAIN_CONTRIBUTION = ChainContribution .builder ()
39- .resultHash ("0x865e1ebff87de7928040a42383b46690a12a988b278eb880e0e641f5da3cc9d1" )
41+ .status (REVEALED )
42+ .resultHash (RESULT_HASH )
4043 .build ();
4144
4245 @ TempDir
@@ -62,46 +65,40 @@ void init() {
6265 void isNotAbleToUploadSinceNoChainContribution () {
6366 when (iexecHubService .isTeeTask (CHAIN_TASK_ID )).thenReturn (false );
6467 when (ipfsResultService .doesResultExist (CHAIN_TASK_ID )).thenReturn (false );
65- when (iexecHubService .isStatusTrueOnChain (CHAIN_TASK_ID , WALLET_ADDRESS , REVEALED )).thenReturn (true );
6668 when (iexecHubService .getChainContribution (CHAIN_TASK_ID , WALLET_ADDRESS )).thenReturn (Optional .empty ());
6769
6870 assertThat (proxyService .canUploadResult (CHAIN_TASK_ID , WALLET_ADDRESS , RESULT_ZIP )).isFalse ();
6971
7072 verify (iexecHubService ).isTeeTask (CHAIN_TASK_ID );
7173 verify (proxyService ).isResultFound (CHAIN_TASK_ID );
72- verify (iexecHubService ).isStatusTrueOnChain (CHAIN_TASK_ID , WALLET_ADDRESS , REVEALED );
7374 verify (iexecHubService ).getChainContribution (CHAIN_TASK_ID , WALLET_ADDRESS );
7475 }
7576
7677 @ Test
7778 void isNotAbleToUploadSinceCannotWriteZip () {
7879 when (iexecHubService .isTeeTask (CHAIN_TASK_ID )).thenReturn (false );
7980 when (ipfsResultService .doesResultExist (CHAIN_TASK_ID )).thenReturn (false );
80- when (iexecHubService .isStatusTrueOnChain (CHAIN_TASK_ID , WALLET_ADDRESS , REVEALED )).thenReturn (true );
8181 when (iexecHubService .getChainContribution (CHAIN_TASK_ID , WALLET_ADDRESS )).thenReturn (Optional .of (CHAIN_CONTRIBUTION ));
8282 when (proxyService .getResultFolderPath (CHAIN_TASK_ID )).thenReturn ("/this/path/does/not/exist" );
8383
8484 assertThat (proxyService .canUploadResult (CHAIN_TASK_ID , WALLET_ADDRESS , RESULT_ZIP )).isFalse ();
8585
8686 verify (iexecHubService ).isTeeTask (CHAIN_TASK_ID );
8787 verify (proxyService ).isResultFound (CHAIN_TASK_ID );
88- verify (iexecHubService ).isStatusTrueOnChain (CHAIN_TASK_ID , WALLET_ADDRESS , REVEALED );
8988 verify (iexecHubService ).getChainContribution (CHAIN_TASK_ID , WALLET_ADDRESS );
9089 }
9190
9291 @ Test
9392 void isNotAbleToUploadSinceWrongHash () {
9493 when (iexecHubService .isTeeTask (CHAIN_TASK_ID )).thenReturn (false );
9594 when (ipfsResultService .doesResultExist (CHAIN_TASK_ID )).thenReturn (false );
96- when (iexecHubService .isStatusTrueOnChain (CHAIN_TASK_ID , WALLET_ADDRESS , REVEALED )).thenReturn (true );
9795 when (iexecHubService .getChainContribution (CHAIN_TASK_ID , WALLET_ADDRESS )).thenReturn (Optional .of (CHAIN_CONTRIBUTION ));
9896 when (proxyService .getResultFolderPath (CHAIN_TASK_ID )).thenReturn (tmpFolder .getAbsolutePath ());
9997
100- assertThat (proxyService .canUploadResult (CHAIN_TASK_ID , WALLET_ADDRESS , new byte [] {})).isFalse ();
98+ assertThat (proxyService .canUploadResult (CHAIN_TASK_ID , WALLET_ADDRESS , new byte []{})).isFalse ();
10199
102100 verify (iexecHubService ).isTeeTask (CHAIN_TASK_ID );
103101 verify (proxyService ).isResultFound (CHAIN_TASK_ID );
104- verify (iexecHubService ).isStatusTrueOnChain (CHAIN_TASK_ID , WALLET_ADDRESS , REVEALED );
105102 verify (iexecHubService ).getChainContribution (CHAIN_TASK_ID , WALLET_ADDRESS );
106103 }
107104
@@ -116,31 +113,28 @@ void isNotAbleToUploadSinceResultAlreadyExistsWithIpfs() {
116113
117114 verify (iexecHubService ).isTeeTask (CHAIN_TASK_ID );
118115 verify (proxyService ).isResultFound (CHAIN_TASK_ID );
119- verify (iexecHubService , never ()).isStatusTrueOnChain (CHAIN_TASK_ID , WALLET_ADDRESS , REVEALED );
120116 verify (iexecHubService , never ()).getChainContribution (CHAIN_TASK_ID , WALLET_ADDRESS );
121117 }
122118
123119 @ Test
124120 void isNotAbleToUploadSinceChainStatusIsNotRevealedWithIpfs () {
121+ ChainContribution chainContribution = ChainContribution .builder ().status (CONTRIBUTED ).resultHash (RESULT_HASH ).build ();
125122 when (iexecHubService .isTeeTask (CHAIN_TASK_ID )).thenReturn (false );
126123 when (ipfsResultService .doesResultExist (CHAIN_TASK_ID )).thenReturn (true );
127- when (iexecHubService .isStatusTrueOnChain (CHAIN_TASK_ID , WALLET_ADDRESS , REVEALED )).thenReturn (false );
128- when (iexecHubService .getChainContribution (CHAIN_TASK_ID , WALLET_ADDRESS )).thenReturn (Optional .of (CHAIN_CONTRIBUTION ));
124+ when (iexecHubService .getChainContribution (CHAIN_TASK_ID , WALLET_ADDRESS )).thenReturn (Optional .of (chainContribution ));
129125 when (proxyService .getResultFolderPath (CHAIN_TASK_ID )).thenReturn (tmpFolder .getAbsolutePath ());
130126
131127 assertThat (proxyService .canUploadResult (CHAIN_TASK_ID , WALLET_ADDRESS , RESULT_ZIP )).isFalse ();
132128
133129 verify (iexecHubService ).isTeeTask (CHAIN_TASK_ID );
134130 verify (proxyService ).isResultFound (CHAIN_TASK_ID );
135- verify (iexecHubService , never ()).isStatusTrueOnChain (CHAIN_TASK_ID , WALLET_ADDRESS , REVEALED );
136131 verify (iexecHubService , never ()).getChainContribution (CHAIN_TASK_ID , WALLET_ADDRESS );
137132 }
138133
139134 @ Test
140135 void isAbleToUploadWithIpfs () {
141136 when (iexecHubService .isTeeTask (CHAIN_TASK_ID )).thenReturn (false );
142137 when (ipfsResultService .doesResultExist (CHAIN_TASK_ID )).thenReturn (false );
143- when (iexecHubService .isStatusTrueOnChain (CHAIN_TASK_ID , WALLET_ADDRESS , REVEALED )).thenReturn (true );
144138 when (iexecHubService .getChainContribution (CHAIN_TASK_ID , WALLET_ADDRESS )).thenReturn (Optional .of (CHAIN_CONTRIBUTION ));
145139 when (proxyService .getResultFolderPath (CHAIN_TASK_ID )).thenReturn (tmpFolder .getAbsolutePath ());
146140
@@ -149,6 +143,5 @@ void isAbleToUploadWithIpfs() {
149143 verify (iexecHubService ).getChainContribution (CHAIN_TASK_ID , WALLET_ADDRESS );
150144 verify (iexecHubService ).isTeeTask (CHAIN_TASK_ID );
151145 verify (proxyService ).isResultFound (CHAIN_TASK_ID );
152- verify (iexecHubService ).isStatusTrueOnChain (CHAIN_TASK_ID , WALLET_ADDRESS , REVEALED );
153146 }
154147}
0 commit comments