1111import java .util .List ;
1212import java .util .concurrent .atomic .AtomicInteger ;
1313import lombok .extern .slf4j .Slf4j ;
14- import org .junit .After ;
14+ import org .junit .AfterClass ;
1515import org .junit .Assert ;
1616import org .junit .Before ;
17+ import org .junit .BeforeClass ;
1718import org .junit .ClassRule ;
1819import org .junit .Test ;
1920import org .junit .rules .TemporaryFolder ;
@@ -63,22 +64,30 @@ public class BlockEventGetTest extends BlockGenerate {
6364 protected Manager dbManager ;
6465 long currentHeader = -1 ;
6566 private TronNetDelegate tronNetDelegate ;
66- private TronApplicationContext context ;
67+ private static TronApplicationContext context ;
6768
6869
6970 static LocalDateTime localDateTime = LocalDateTime .now ();
7071 private long time = ZonedDateTime .of (localDateTime ,
7172 ZoneId .systemDefault ()).toInstant ().toEpochMilli ();
7273
73- protected void initDbPath () throws IOException {
74- dbPath = temporaryFolder .newFolder ().toString ();
74+
75+ public static String dbPath () {
76+ try {
77+ return temporaryFolder .newFolder ().toString ();
78+ } catch (IOException e ) {
79+ Assert .fail ("create temp folder failed" );
80+ }
81+ return null ;
82+ }
83+
84+ @ BeforeClass
85+ public static void init () {
86+ Args .setParam (new String [] {"--output-directory" , dbPath ()}, Constant .TEST_CONF );
7587 }
7688
7789 @ Before
7890 public void before () throws IOException {
79- initDbPath ();
80- logger .info ("Full node running." );
81- Args .setParam (new String [] {"-d" , dbPath }, Constant .TEST_CONF );
8291 Args .getInstance ().setNodeListenPort (10000 + port .incrementAndGet ());
8392
8493 context = new TronApplicationContext (DefaultConfig .class );
@@ -91,7 +100,7 @@ public void before() throws IOException {
91100 tronNetDelegate = context .getBean (TronNetDelegate .class );
92101 tronNetDelegate .setExit (false );
93102 currentHeader = dbManager .getDynamicPropertiesStore ()
94- .getLatestBlockHeaderNumberFromDB ();
103+ .getLatestBlockHeaderNumberFromDB ();
95104
96105 ByteString addressBS = ByteString .copyFrom (address );
97106 WitnessCapsule witnessCapsule = new WitnessCapsule (addressBS );
@@ -108,8 +117,10 @@ public void before() throws IOException {
108117 dps .saveAllowTvmShangHai (1 );
109118 }
110119
111- @ After
112- public void after () throws IOException {
120+ @ AfterClass
121+ public static void after () throws IOException {
122+ context .destroy ();
123+ Args .clearParam ();
113124 }
114125
115126 @ Test
@@ -132,13 +143,13 @@ public void test() throws Exception {
132143 + "57c973388f044038eff0e6474425b38037e75e66d6b3047647290605449c7764736f6c63430008140033" ;
133144 Protocol .Transaction trx = TvmTestUtils .generateDeploySmartContractAndGetTransaction (
134145 "TestTRC20" , address , "[{\" anonymous\" :false,\" inputs\" :[{\" indexed\" :true,\" name\" "
135- + ":\" from\" ,\" type\" :\" address\" },{\" indexed\" :true,\" name\" :\" to\" ,\" type\" :\" address\" }"
136- + ",{\" indexed\" :false,\" name\" :\" value\" ,\" type\" :\" uint256\" }],\" name\" :\" Transfer\" ,"
137- + "\" type\" :\" event\" }]" , code , 0 , (long ) 1e9 , 100 , null , 1 );
146+ + ":\" from\" ,\" type\" :\" address\" },{\" indexed\" :true,\" name\" :\" to\" ,\" type\" :\" address\" }"
147+ + ",{\" indexed\" :false,\" name\" :\" value\" ,\" type\" :\" uint256\" }],\" name\" :\" Transfer\" ,"
148+ + "\" type\" :\" event\" }]" , code , 0 , (long ) 1e9 , 100 , null , 1 );
138149 trx = trx .toBuilder ().addRet (
139- Protocol .Transaction .Result .newBuilder ()
140- .setContractRetValue (Protocol .Transaction .Result .contractResult .SUCCESS_VALUE )
141- .build ()).build ();
150+ Protocol .Transaction .Result .newBuilder ()
151+ .setContractRetValue (Protocol .Transaction .Result .contractResult .SUCCESS_VALUE )
152+ .build ()).build ();
142153
143154 Protocol .Block block = getSignedBlock (witnessCapsule .getAddress (), time , privateKey );
144155 BlockCapsule blockCapsule = new BlockCapsule (block .toBuilder ().addTransactions (trx ).build ());
0 commit comments