Skip to content

Commit 88faef4

Browse files
committed
change Runtime test.
(cherry picked from commit e0ccd0b)
1 parent 6ee1f55 commit 88faef4

6 files changed

Lines changed: 67 additions & 56 deletions

File tree

‎src/test/java/org/tron/common/runtime/TVMTestUtils.java‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ public static Runtime processTransactionAndReturnRuntime(Transaction trx,
9494
throws ContractExeException, ContractValidateException, ReceiptCheckErrException, VMIllegalException {
9595
TransactionCapsule trxCap = new TransactionCapsule(trx);
9696
TransactionTrace trace = new TransactionTrace(trxCap, deposit.getDbManager());
97-
Runtime runtime = new Runtime(trace, block, deposit,
97+
Runtime runtime = new RuntimeImpl(trace, block, deposit,
9898
new ProgramInvokeFactoryImpl());
9999

100100
// init
101-
trace.init();
101+
trace.init(block);
102102
//exec
103-
trace.exec(runtime);
103+
trace.exec();
104104

105-
trace.finalization(runtime);
105+
trace.finalization();
106106

107107
return runtime;
108108
}
@@ -139,15 +139,15 @@ public static TVMTestResult processTransactionAndReturnTVMTestResult(Transaction
139139
TransactionCapsule trxCap = new TransactionCapsule(trx);
140140
TransactionTrace trace = new TransactionTrace(trxCap, dbManager);
141141
DepositImpl deposit = DepositImpl.createRoot(dbManager);
142-
Runtime runtime = new Runtime(trace, blockCap, deposit,
142+
Runtime runtime = new RuntimeImpl(trace, blockCap, deposit,
143143
new ProgramInvokeFactoryImpl());
144144

145145
// init
146-
trace.init();
146+
trace.init(blockCap);
147147
//exec
148-
trace.exec(runtime);
148+
trace.exec();
149149

150-
trace.finalization(runtime);
150+
trace.finalization();
151151

152152
return new TVMTestResult(runtime, trace.getReceipt(), null);
153153
}

‎src/test/java/org/tron/common/runtime/vm/BandWidthRuntimeOutOfTimeTest.java‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.tron.common.application.ApplicationFactory;
2727
import org.tron.common.application.TronApplicationContext;
2828
import org.tron.common.runtime.Runtime;
29+
import org.tron.common.runtime.RuntimeImpl;
2930
import org.tron.common.runtime.TVMTestUtils;
3031
import org.tron.common.runtime.vm.program.invoke.ProgramInvokeFactoryImpl;
3132
import org.tron.common.storage.DepositImpl;
@@ -145,10 +146,11 @@ public void testSuccess() {
145146
dbManager.consumeBandwidth(trxCap, trace);
146147
BlockCapsule blockCapsule = null;
147148
DepositImpl deposit = DepositImpl.createRoot(dbManager);
148-
Runtime runtime = new Runtime(trace, blockCapsule, deposit, new ProgramInvokeFactoryImpl());
149-
trace.init();
150-
trace.exec(runtime);
151-
trace.finalization(runtime);
149+
Runtime runtime = new RuntimeImpl(trace, blockCapsule, deposit,
150+
new ProgramInvokeFactoryImpl());
151+
trace.init(blockCapsule);
152+
trace.exec();
153+
trace.finalization();
152154

153155
triggerOwner = dbManager.getAccountStore()
154156
.get(Wallet.decodeFromBase58Check(TriggerOwnerAddress));
@@ -186,10 +188,10 @@ private byte[] createContract()
186188
dbManager.consumeBandwidth(trxCap, trace);
187189
BlockCapsule blockCapsule = null;
188190
DepositImpl deposit = DepositImpl.createRoot(dbManager);
189-
Runtime runtime = new Runtime(trace, blockCapsule, deposit, new ProgramInvokeFactoryImpl());
190-
trace.init();
191-
trace.exec(runtime);
192-
trace.finalization(runtime);
191+
Runtime runtime = new RuntimeImpl(trace, blockCapsule, deposit, new ProgramInvokeFactoryImpl());
192+
trace.init(blockCapsule);
193+
trace.exec();
194+
trace.finalization();
193195
owner = dbManager.getAccountStore()
194196
.get(Wallet.decodeFromBase58Check(OwnerAddress));
195197
energy = owner.getEnergyUsage() - energy;

‎src/test/java/org/tron/common/runtime/vm/BandWidthRuntimeOutOfTimeWithCheckTest.java‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.tron.common.application.ApplicationFactory;
2727
import org.tron.common.application.TronApplicationContext;
2828
import org.tron.common.runtime.Runtime;
29+
import org.tron.common.runtime.RuntimeImpl;
2930
import org.tron.common.runtime.TVMTestUtils;
3031
import org.tron.common.runtime.vm.program.invoke.ProgramInvokeFactoryImpl;
3132
import org.tron.common.storage.DepositImpl;
@@ -147,10 +148,11 @@ public void testSuccess() {
147148
dbManager.consumeBandwidth(trxCap, trace);
148149
BlockCapsule blockCapsule = null;
149150
DepositImpl deposit = DepositImpl.createRoot(dbManager);
150-
Runtime runtime = new Runtime(trace, blockCapsule, deposit, new ProgramInvokeFactoryImpl());
151-
trace.init();
152-
trace.exec(runtime);
153-
trace.finalization(runtime);
151+
Runtime runtime = new RuntimeImpl(trace, blockCapsule, deposit,
152+
new ProgramInvokeFactoryImpl());
153+
trace.init(blockCapsule);
154+
trace.exec();
155+
trace.finalization();
154156
trace.check();
155157
triggerOwner = dbManager.getAccountStore()
156158
.get(Wallet.decodeFromBase58Check(TriggerOwnerAddress));
@@ -190,10 +192,10 @@ private byte[] createContract()
190192
dbManager.consumeBandwidth(trxCap, trace);
191193
BlockCapsule blockCapsule = null;
192194
DepositImpl deposit = DepositImpl.createRoot(dbManager);
193-
Runtime runtime = new Runtime(trace, blockCapsule, deposit, new ProgramInvokeFactoryImpl());
194-
trace.init();
195-
trace.exec(runtime);
196-
trace.finalization(runtime);
195+
Runtime runtime = new RuntimeImpl(trace, blockCapsule, deposit, new ProgramInvokeFactoryImpl());
196+
trace.init(blockCapsule);
197+
trace.exec();
198+
trace.finalization();
197199
owner = dbManager.getAccountStore()
198200
.get(Wallet.decodeFromBase58Check(OwnerAddress));
199201
energy = owner.getEnergyUsage() - energy;

‎src/test/java/org/tron/common/runtime/vm/BandWidthRuntimeTest.java‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.tron.common.application.ApplicationFactory;
2727
import org.tron.common.application.TronApplicationContext;
2828
import org.tron.common.runtime.Runtime;
29+
import org.tron.common.runtime.RuntimeImpl;
2930
import org.tron.common.runtime.TVMTestUtils;
3031
import org.tron.common.runtime.vm.program.invoke.ProgramInvokeFactoryImpl;
3132
import org.tron.common.storage.DepositImpl;
@@ -151,10 +152,11 @@ public void testSuccess() {
151152
dbManager.consumeBandwidth(trxCap, trace);
152153
BlockCapsule blockCapsule = null;
153154
DepositImpl deposit = DepositImpl.createRoot(dbManager);
154-
Runtime runtime = new Runtime(trace, blockCapsule, deposit, new ProgramInvokeFactoryImpl());
155-
trace.init();
156-
trace.exec(runtime);
157-
trace.finalization(runtime);
155+
Runtime runtime = new RuntimeImpl(trace, blockCapsule, deposit,
156+
new ProgramInvokeFactoryImpl());
157+
trace.init(blockCapsule);
158+
trace.exec();
159+
trace.finalization();
158160

159161
triggerOwner = dbManager.getAccountStore()
160162
.get(Wallet.decodeFromBase58Check(TriggerOwnerAddress));
@@ -184,10 +186,11 @@ public void testSuccessNoBandd() {
184186
long bandWidth = trxCap.getSerializedSize() + Constant.MAX_RESULT_SIZE_IN_TX;
185187
BlockCapsule blockCapsule = null;
186188
DepositImpl deposit = DepositImpl.createRoot(dbManager);
187-
Runtime runtime = new Runtime(trace, blockCapsule, deposit, new ProgramInvokeFactoryImpl());
188-
trace.init();
189-
trace.exec(runtime);
190-
trace.finalization(runtime);
189+
Runtime runtime = new RuntimeImpl(trace, blockCapsule, deposit,
190+
new ProgramInvokeFactoryImpl());
191+
trace.init(blockCapsule);
192+
trace.exec();
193+
trace.finalization();
191194

192195
AccountCapsule triggerOwnerTwo = dbManager.getAccountStore()
193196
.get(Wallet.decodeFromBase58Check(TriggerOwnerTwoAddress));
@@ -225,10 +228,10 @@ private byte[] createContract()
225228
dbManager.consumeBandwidth(trxCap, trace);
226229
BlockCapsule blockCapsule = null;
227230
DepositImpl deposit = DepositImpl.createRoot(dbManager);
228-
Runtime runtime = new Runtime(trace, blockCapsule, deposit, new ProgramInvokeFactoryImpl());
229-
trace.init();
230-
trace.exec(runtime);
231-
trace.finalization(runtime);
231+
Runtime runtime = new RuntimeImpl(trace, blockCapsule, deposit, new ProgramInvokeFactoryImpl());
232+
trace.init(blockCapsule);
233+
trace.exec();
234+
trace.finalization();
232235
owner = dbManager.getAccountStore()
233236
.get(Wallet.decodeFromBase58Check(OwnerAddress));
234237
energy = owner.getEnergyUsage() - energy;

‎src/test/java/org/tron/common/runtime/vm/BandWidthRuntimeWithCheckTest.java‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.tron.common.application.ApplicationFactory;
2727
import org.tron.common.application.TronApplicationContext;
2828
import org.tron.common.runtime.Runtime;
29+
import org.tron.common.runtime.RuntimeImpl;
2930
import org.tron.common.runtime.TVMTestUtils;
3031
import org.tron.common.runtime.vm.program.invoke.ProgramInvokeFactoryImpl;
3132
import org.tron.common.storage.DepositImpl;
@@ -154,10 +155,11 @@ public void testSuccess() {
154155
dbManager.consumeBandwidth(trxCap, trace);
155156
BlockCapsule blockCapsule = null;
156157
DepositImpl deposit = DepositImpl.createRoot(dbManager);
157-
Runtime runtime = new Runtime(trace, blockCapsule, deposit, new ProgramInvokeFactoryImpl());
158-
trace.init();
159-
trace.exec(runtime);
160-
trace.finalization(runtime);
158+
Runtime runtime = new RuntimeImpl(trace, blockCapsule, deposit,
159+
new ProgramInvokeFactoryImpl());
160+
trace.init(blockCapsule);
161+
trace.exec();
162+
trace.finalization();
161163

162164
triggerOwner = dbManager.getAccountStore()
163165
.get(Wallet.decodeFromBase58Check(TriggerOwnerAddress));
@@ -193,10 +195,11 @@ public void testSuccessNoBandWidth() {
193195
long bandWidth = trxCap.getSerializedSize() + Constant.MAX_RESULT_SIZE_IN_TX;
194196
BlockCapsule blockCapsule = null;
195197
DepositImpl deposit = DepositImpl.createRoot(dbManager);
196-
Runtime runtime = new Runtime(trace, blockCapsule, deposit, new ProgramInvokeFactoryImpl());
197-
trace.init();
198-
trace.exec(runtime);
199-
trace.finalization(runtime);
198+
Runtime runtime = new RuntimeImpl(trace, blockCapsule, deposit,
199+
new ProgramInvokeFactoryImpl());
200+
trace.init(blockCapsule);
201+
trace.exec();
202+
trace.finalization();
200203
trace.check();
201204
AccountCapsule triggerOwnerTwo = dbManager.getAccountStore()
202205
.get(Wallet.decodeFromBase58Check(TriggerOwnerTwoAddress));
@@ -237,10 +240,10 @@ private byte[] createContract()
237240
dbManager.consumeBandwidth(trxCap, trace);
238241
BlockCapsule blockCapsule = null;
239242
DepositImpl deposit = DepositImpl.createRoot(dbManager);
240-
Runtime runtime = new Runtime(trace, blockCapsule, deposit, new ProgramInvokeFactoryImpl());
241-
trace.init();
242-
trace.exec(runtime);
243-
trace.finalization(runtime);
243+
Runtime runtime = new RuntimeImpl(trace, blockCapsule, deposit, new ProgramInvokeFactoryImpl());
244+
trace.init(blockCapsule);
245+
trace.exec();
246+
trace.finalization();
244247
trace.check();
245248

246249
owner = dbManager.getAccountStore()

‎src/test/java/org/tron/core/db/TransactionTraceTest.java‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
2828
import org.tron.common.application.TronApplicationContext;
2929
import org.tron.common.runtime.Runtime;
30+
import org.tron.common.runtime.RuntimeImpl;
3031
import org.tron.common.runtime.vm.program.invoke.ProgramInvokeFactoryImpl;
3132
import org.tron.common.storage.DepositImpl;
3233
import org.tron.common.utils.ByteArray;
@@ -128,10 +129,10 @@ public void testUseUsage() throws InvalidProtocolBufferException, VMIllegalExcep
128129
TransactionCapsule transactionCapsule = new TransactionCapsule(transaction);
129130
TransactionTrace trace = new TransactionTrace(transactionCapsule, dbManager);
130131
DepositImpl deposit = DepositImpl.createRoot(dbManager);
131-
Runtime runtime = new Runtime(trace, null, deposit,
132+
Runtime runtime = new RuntimeImpl(trace, null, deposit,
132133
new ProgramInvokeFactoryImpl());
133134
try {
134-
trace.exec(runtime);
135+
trace.exec();
135136
trace.pay();
136137
Assert.assertEquals(50000, trace.getReceipt().getEnergyUsage());
137138
Assert.assertEquals(20110013100L, trace.getReceipt().getEnergyFee());
@@ -166,10 +167,10 @@ public void testTriggerUseFee() throws InvalidProtocolBufferException {
166167
TransactionCapsule transactionCapsule = new TransactionCapsule(transaction);
167168
TransactionTrace trace = new TransactionTrace(transactionCapsule, dbManager);
168169
DepositImpl deposit = DepositImpl.createRoot(dbManager);
169-
Runtime runtime = new Runtime(trace, null, deposit,
170+
Runtime runtime = new RuntimeImpl(trace, null, deposit,
170171
new ProgramInvokeFactoryImpl());
171172
try {
172-
trace.exec(runtime);
173+
trace.exec();
173174
trace.pay();
174175
Assert.assertEquals(0, trace.getReceipt().getEnergyUsage());
175176
Assert.assertEquals(2024300, trace.getReceipt().getEnergyFee());
@@ -203,10 +204,10 @@ public void testTriggerUseUsage() throws InvalidProtocolBufferException {
203204
TransactionCapsule transactionCapsule = new TransactionCapsule(transaction);
204205
TransactionTrace trace = new TransactionTrace(transactionCapsule, dbManager);
205206
DepositImpl deposit = DepositImpl.createRoot(dbManager);
206-
Runtime runtime = new Runtime(trace, null, deposit,
207+
Runtime runtime = new RuntimeImpl(trace, null, deposit,
207208
new ProgramInvokeFactoryImpl());
208209
try {
209-
trace.exec(runtime);
210+
trace.exec();
210211
trace.pay();
211212
Assert.assertEquals(5243, trace.getReceipt().getEnergyUsage());
212213
Assert.assertEquals(0, trace.getReceipt().getEnergyFee());
@@ -242,10 +243,10 @@ private void deployInit(String trxDeploy2Byte)
242243
TransactionCapsule transactionCapsule = new TransactionCapsule(transaction);
243244
TransactionTrace trace = new TransactionTrace(transactionCapsule, dbManager);
244245
DepositImpl deposit = DepositImpl.createRoot(dbManager);
245-
Runtime runtime = new Runtime(trace, null, deposit,
246+
Runtime runtime = new RuntimeImpl(trace, null, deposit,
246247
new ProgramInvokeFactoryImpl());
247248
try {
248-
trace.exec(runtime);
249+
trace.exec();
249250
trace.pay();
250251
Assert.assertEquals(0, trace.getReceipt().getEnergyUsage());
251252
Assert.assertEquals(20115013100L, trace.getReceipt().getEnergyFee());

0 commit comments

Comments
 (0)