Skip to content

Commit a3fa6e7

Browse files
committed
Test all Taker BTC cases
- takerCheckFeeAddressBtcInvalidFeeAddress - takerCheckFeeAddressBtcTooOldValidFee - takerExactFeeMatchBtcTest - takerHigherBtcFeeThanExpected - takerLowerButWithinToleranceBtcFee - takerPassFilterFeeCheck - takerFailFilterFeeCheck - takerNoFilterFeeMatchesDifferentDaoParameter - takerNoFilterFeeTooLow
1 parent 6e05fc7 commit a3fa6e7

File tree

1 file changed

+148
-0
lines changed

1 file changed

+148
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/*
2+
* This file is part of Bisq.
3+
*
4+
* Bisq is free software: you can redistribute it and/or modify it
5+
* under the terms of the GNU Affero General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or (at
7+
* your option) any later version.
8+
*
9+
* Bisq is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
12+
* License for more details.
13+
*
14+
* You should have received a copy of the GNU Affero General Public License
15+
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package bisq.core.fee;
19+
20+
import bisq.core.dao.state.DaoStateService;
21+
import bisq.core.filter.Filter;
22+
import bisq.core.filter.FilterManager;
23+
import bisq.core.provider.mempool.FeeValidationStatus;
24+
import bisq.core.provider.mempool.TxValidator;
25+
26+
import org.bitcoinj.core.Coin;
27+
28+
import java.util.Collections;
29+
import java.util.List;
30+
31+
import org.mockito.Mock;
32+
import org.mockito.junit.jupiter.MockitoExtension;
33+
34+
import org.junit.jupiter.api.BeforeEach;
35+
import org.junit.jupiter.api.Test;
36+
import org.junit.jupiter.api.extension.ExtendWith;
37+
38+
import static org.hamcrest.CoreMatchers.is;
39+
import static org.hamcrest.MatcherAssert.assertThat;
40+
import static org.mockito.ArgumentMatchers.any;
41+
import static org.mockito.ArgumentMatchers.anyInt;
42+
import static org.mockito.ArgumentMatchers.anyString;
43+
import static org.mockito.Mockito.doReturn;
44+
import static org.mockito.Mockito.mock;
45+
46+
@ExtendWith(MockitoExtension.class)
47+
public class TakerFeeBtcValidationTests {
48+
private static final List<String> BTC_FEE_RECEIVERS = List.of("2MzBNTJDjjXgViKBGnatDU3yWkJ8pJkEg9w");
49+
private static final String VALID_MAKER_FEE_JSON_RESPONSE = MakerTxValidatorSanityCheckTests.getValidBtcMakerFeeMempoolJsonResponseString();
50+
@Mock
51+
private DaoStateService daoStateService;
52+
@Mock
53+
private FilterManager filterManager;
54+
private TxValidator txValidator;
55+
56+
@BeforeEach
57+
void setup() {
58+
String txId = "e3607e971ead7d03619e3a9eeaa771ed5adba14c448839e0299f857f7bb4ec07";
59+
txValidator = new TxValidator(daoStateService, txId,
60+
Coin.valueOf(100000), true, 143, filterManager);
61+
}
62+
63+
@Test
64+
void takerCheckFeeAddressBtcTooOldValidFee() {
65+
doReturn(Coin.valueOf(5000)).when(daoStateService).getParamValueAsCoin(any(), anyInt());
66+
doReturn(Coin.valueOf(5000)).when(daoStateService).getParamValueAsCoin(any(), anyString());
67+
68+
TxValidator txValidator1 = txValidator.parseJsonValidateTakerFeeTx(VALID_MAKER_FEE_JSON_RESPONSE, Collections.emptyList());
69+
assertThat(txValidator1.getStatus(), is(FeeValidationStatus.ACK_FEE_OK));
70+
}
71+
72+
@Test
73+
void takerExactFeeMatchBtcTest() {
74+
doReturn(Coin.valueOf(5000)).when(daoStateService).getParamValueAsCoin(any(), anyInt());
75+
doReturn(Coin.valueOf(5000)).when(daoStateService).getParamValueAsCoin(any(), anyString());
76+
77+
TxValidator txValidator1 = txValidator.parseJsonValidateTakerFeeTx(VALID_MAKER_FEE_JSON_RESPONSE, BTC_FEE_RECEIVERS);
78+
assertThat(txValidator1.getStatus(), is(FeeValidationStatus.ACK_FEE_OK));
79+
}
80+
81+
@Test
82+
void takerHigherBtcFeeThanExpected() {
83+
doReturn(Coin.valueOf(4000)).when(daoStateService).getParamValueAsCoin(any(), anyInt());
84+
doReturn(Coin.valueOf(4000)).when(daoStateService).getParamValueAsCoin(any(), anyString());
85+
86+
TxValidator txValidator1 = txValidator.parseJsonValidateTakerFeeTx(VALID_MAKER_FEE_JSON_RESPONSE, BTC_FEE_RECEIVERS);
87+
assertThat(txValidator1.getStatus(), is(FeeValidationStatus.ACK_FEE_OK));
88+
}
89+
90+
@Test
91+
void takerLowerButWithinToleranceBtcFee() {
92+
doReturn(Coin.valueOf(5001)).when(daoStateService).getParamValueAsCoin(any(), anyInt());
93+
doReturn(Coin.valueOf(5001)).when(daoStateService).getParamValueAsCoin(any(), anyString());
94+
95+
TxValidator txValidator1 = txValidator.parseJsonValidateTakerFeeTx(VALID_MAKER_FEE_JSON_RESPONSE, BTC_FEE_RECEIVERS);
96+
assertThat(txValidator1.getStatus(), is(FeeValidationStatus.ACK_FEE_OK));
97+
}
98+
99+
@Test
100+
void takerPassFilterFeeCheck() {
101+
doReturn(Coin.valueOf(10_000), Coin.valueOf(5_000)).when(daoStateService).getParamValueAsCoin(any(), anyInt());
102+
doReturn(Coin.valueOf(10_000), Coin.valueOf(5_000)).when(daoStateService).getParamValueAsCoin(any(), anyString());
103+
104+
Filter filter = mock(Filter.class);
105+
doReturn(5_000_000L).when(filter).getTakerFeeBtc();
106+
doReturn(filter).when(filterManager).getFilter();
107+
108+
TxValidator txValidator1 = txValidator.parseJsonValidateTakerFeeTx(VALID_MAKER_FEE_JSON_RESPONSE, BTC_FEE_RECEIVERS);
109+
assertThat(txValidator1.getStatus(), is(FeeValidationStatus.ACK_FEE_OK));
110+
}
111+
112+
@Test
113+
void takerFailFilterFeeCheck() {
114+
doReturn(Coin.valueOf(10_000)).when(daoStateService).getParamValueAsCoin(any(), anyInt());
115+
doReturn(Coin.valueOf(10_000)).when(daoStateService).getParamValueAsCoin(any(), anyString());
116+
117+
Filter filter = mock(Filter.class);
118+
doReturn(10_000_000L).when(filter).getTakerFeeBtc();
119+
doReturn(filter).when(filterManager).getFilter();
120+
121+
TxValidator txValidator1 = txValidator.parseJsonValidateTakerFeeTx(VALID_MAKER_FEE_JSON_RESPONSE, BTC_FEE_RECEIVERS);
122+
assertThat(txValidator1.getStatus(), is(FeeValidationStatus.NACK_TAKER_FEE_TOO_LOW));
123+
}
124+
125+
@Test
126+
void takerNoFilterFeeMatchesDifferentDaoParameter() {
127+
doReturn(Coin.valueOf(10_000), Coin.valueOf(5_000)).when(daoStateService).getParamValueAsCoin(any(), anyInt());
128+
doReturn(Coin.valueOf(10_000), Coin.valueOf(5_000)).when(daoStateService).getParamValueAsCoin(any(), anyString());
129+
130+
doReturn(null).when(filterManager).getFilter();
131+
doReturn(List.of(Coin.valueOf(5_000))).when(daoStateService).getParamChangeList(any());
132+
133+
TxValidator txValidator1 = txValidator.parseJsonValidateTakerFeeTx(VALID_MAKER_FEE_JSON_RESPONSE, BTC_FEE_RECEIVERS);
134+
assertThat(txValidator1.getStatus(), is(FeeValidationStatus.ACK_FEE_OK));
135+
}
136+
137+
@Test
138+
void takerNoFilterFeeTooLow() {
139+
doReturn(Coin.valueOf(10_000)).when(daoStateService).getParamValueAsCoin(any(), anyInt());
140+
doReturn(Coin.valueOf(10_000)).when(daoStateService).getParamValueAsCoin(any(), anyString());
141+
142+
doReturn(null).when(filterManager).getFilter();
143+
doReturn(List.of(Coin.valueOf(5_000))).when(daoStateService).getParamChangeList(any());
144+
145+
TxValidator txValidator1 = txValidator.parseJsonValidateTakerFeeTx(VALID_MAKER_FEE_JSON_RESPONSE, BTC_FEE_RECEIVERS);
146+
assertThat(txValidator1.getStatus(), is(FeeValidationStatus.NACK_TAKER_FEE_TOO_LOW));
147+
}
148+
}

0 commit comments

Comments
 (0)