Skip to content

Commit 4cacc82

Browse files
authored
Merge pull request tronprotocol#34 from seanrobbins/develop
Use a mock for UTXOSet in Blockchain test
2 parents 9ac415c + c4d0e1f commit 4cacc82

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/test/java/org/tron/core/BlockchainTest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.junit.AfterClass;
2020
import org.junit.BeforeClass;
2121
import org.junit.Test;
22+
import org.mockito.Mockito;
2223
import org.slf4j.Logger;
2324
import org.slf4j.LoggerFactory;
2425
import org.tron.protos.core.TronBlock.Block;
@@ -104,11 +105,19 @@ public void testDBExists() {
104105

105106
@Test
106107
public void testFindUTXO() {
108+
long testAmount = 10;
107109
Wallet wallet = new Wallet();
108110
wallet.init();
109-
UTXOSet utxoSet = new UTXOSet();
111+
SpendableOutputs spendableOutputs = new SpendableOutputs();
112+
spendableOutputs.setAmount(testAmount + 1);
113+
spendableOutputs.setUnspentOutputs(new HashMap<>());
114+
UTXOSet mockUtxoSet = Mockito.mock(UTXOSet.class);
115+
Mockito.when(mockUtxoSet.findSpendableOutputs(wallet.getEcKey().getPubKey(), testAmount)
116+
).thenReturn(spendableOutputs);
117+
Mockito.when(mockUtxoSet.getBlockchain()).thenReturn(blockchain);
118+
110119
Transaction transaction = TransactionUtils.newTransaction(wallet,
111-
"fd0f3c8ab4877f0fd96cd156b0ad42ea7aa82c31", 10, utxoSet);
120+
"fd0f3c8ab4877f0fd96cd156b0ad42ea7aa82c31", testAmount, mockUtxoSet);
112121
List<Transaction> transactions = new ArrayList<>();
113122
transactions.add(transaction);
114123
blockchain.addBlock(BlockUtils.newBlock(transactions, ByteString

0 commit comments

Comments
 (0)