Skip to content

Commit 779493b

Browse files
committed
move to be a unit test
Signed-off-by: Josh Marinacci <[email protected]>
1 parent eb4da7d commit 779493b

File tree

1 file changed

+35
-9
lines changed

1 file changed

+35
-9
lines changed

hedera-node/hedera-app/src/main/java/com/hedera/node/app/examples/SimpleFeesMirrorNodeExample.java renamed to hedera-node/hedera-app/src/test/java/com/hedera/node/app/fees/SimpleFeesMirrorNodeTest.java

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
package com.hedera.node.app.examples;
1+
package com.hedera.node.app.fees;
22

3+
import com.hedera.hapi.node.consensus.ConsensusCreateTopicTransactionBody;
4+
import org.junit.jupiter.api.Test;
5+
6+
import com.hedera.hapi.node.base.TopicID;
7+
import com.hedera.hapi.node.consensus.ConsensusSubmitMessageTransactionBody;
38
import com.hedera.node.app.service.consensus.impl.ConsensusServiceImpl;
49
import com.hedera.node.app.service.schedule.impl.ScheduleServiceImpl;
510
import com.hedera.node.app.service.token.impl.TokenServiceImpl;
611
import org.hiero.hapi.support.fees.FeeSchedule;
7-
import com.hedera.hapi.node.consensus.ConsensusCreateTopicTransactionBody;
812
import com.hedera.hapi.node.transaction.TransactionBody;
913
import com.hedera.node.app.spi.fees.FeeContext;
1014
import com.hedera.node.app.spi.fees.QueryFeeCalculator;
@@ -16,6 +20,8 @@
1620
import com.hedera.pbj.runtime.ParseException;
1721
import com.hedera.pbj.runtime.io.buffer.Bytes;
1822
import org.hiero.hapi.fees.FeeResult;
23+
import org.junit.jupiter.api.extension.ExtendWith;
24+
import org.mockito.junit.jupiter.MockitoExtension;
1925

2026
import java.io.IOException;
2127
import java.util.HashSet;
@@ -42,11 +48,18 @@
4248
others like CryptoServiceImpl are not. And some impls need a bunch of parameters to init. Instead
4349
let's have static lists of fee calculators on each service impl.
4450
45-
How do I call this main method from within gradle?
51+
How do I call this main method from within gradle? For now I'll make it be a unit test.
52+
53+
54+
The FeeContext is going to be a challenge. Some calculators need the fee context, not just for the
55+
number of sigs but also for the readable store so they can get, for example, the topic a message
56+
is being submitted to so it can determine if there are custom fees applied.
4657
4758
4859
*/
49-
public class SimpleFeesMirrorNodeExample {
60+
61+
@ExtendWith(MockitoExtension.class)
62+
public class SimpleFeesMirrorNodeTest {
5063

5164
static class SimpleFeesCalculatorProvider {
5265
SimpleFeeCalculator make(FeeSchedule feeSchedule) {
@@ -67,11 +80,12 @@ SimpleFeeCalculator make(FeeSchedule feeSchedule) {
6780
}
6881
}
6982

70-
public static void main(String[] args) throws IOException, ParseException {
83+
@Test
84+
public void doTest() throws IOException, ParseException {
7185
System.out.println("calculating a fee for a create topic transaction");
7286

7387
// load up the fee schedule from JSON file
74-
var input = SimpleFeesMirrorNodeExample.class.getClassLoader().getResourceAsStream("test-schedule.json");
88+
var input = SimpleFeesMirrorNodeTest.class.getClassLoader().getResourceAsStream("test-schedule.json");
7589
var bytes = input.readAllBytes();
7690
final FeeSchedule feeSchedule = FeeSchedule.JSON.parse(Bytes.wrap(bytes));
7791

@@ -85,11 +99,23 @@ public static void main(String[] args) throws IOException, ParseException {
8599
SimpleFeeCalculator calc = new SimpleFeesCalculatorProvider().make(feeSchedule);
86100

87101
// build an example transaction
88-
final var op = ConsensusCreateTopicTransactionBody.newBuilder().build();
89-
final var txnBody = TransactionBody.newBuilder().consensusCreateTopic(op).build();
102+
// final var op = ConsensusCreateTopicTransactionBody.newBuilder().build();
103+
// final var txnBody = TransactionBody.newBuilder().consensusCreateTopic(op).build();
104+
// final var txn = Transaction.newBuilder().body(txnBody).build();
105+
// final var numSigs = txn.sigMap().sigPair().size();
106+
final long topicEntityNum = 1L;
107+
final TopicID topicId =
108+
TopicID.newBuilder().topicNum(topicEntityNum).build();
109+
110+
final var op = ConsensusSubmitMessageTransactionBody.newBuilder()
111+
.topicID(topicId)
112+
.message(Bytes.wrap("foo"))
113+
.build();
114+
final var txnBody =
115+
TransactionBody.newBuilder().consensusSubmitMessage(op).build();
90116

91117
// create a fee context
92-
FeeContext feeContext = null;
118+
FeeContext feeContext = null;//new FeeContextImpl()
93119

94120
FeeResult result = calc.calculateTxFee(txnBody, feeContext);
95121
System.out.println("the fees are " + result);

0 commit comments

Comments
 (0)