11package org .tron .core .services .http ;
22
33import com .google .gson .JsonObject ;
4- import java . io . File ;
4+ import javax . annotation . Resource ;
55import lombok .extern .slf4j .Slf4j ;
66import org .apache .http .HttpResponse ;
77import org .bouncycastle .util .encoders .Hex ;
8- import org .junit .AfterClass ;
8+ import org .junit .Before ;
99import org .junit .BeforeClass ;
1010import org .junit .Test ;
1111import org .springframework .beans .factory .support .DefaultListableBeanFactory ;
12+ import org .tron .common .BaseTest ;
1213import org .tron .common .application .Application ;
13- import org .tron .common .application .ApplicationFactory ;
14- import org .tron .common .application .TronApplicationContext ;
1514import org .tron .common .utils .ByteArray ;
16- import org .tron .common .utils .FileUtil ;
1715import org .tron .core .Constant ;
1816import org .tron .core .capsule .ContractCapsule ;
19- import org .tron .core .config .DefaultConfig ;
2017import org .tron .core .config .args .Args ;
2118import org .tron .core .store .StoreFactory ;
2219import org .tron .core .vm .repository .Repository ;
2320import org .tron .core .vm .repository .RepositoryImpl ;
2421import org .tron .protos .Protocol ;
2522import org .tron .protos .contract .SmartContractOuterClass ;
23+ import stest .tron .wallet .common .client .Configuration ;
2624import stest .tron .wallet .common .client .utils .HttpMethed ;
2725
2826@ Slf4j
29- public class TriggerSmartContractServletTest {
27+ public class TriggerSmartContractServletTest extends BaseTest {
28+ private static final String httpNode = Configuration .getByPath ("testng.conf" )
29+ .getStringList ("httpnode.ip.list" )
30+ .get (0 );
31+ private static final byte [] ownerAddr = Hex .decode ("410000000000000000000000000000000000000000" );
32+ private static final byte [] contractAddr = Hex .decode (
33+ "41000000000000000000000000000000000000dEaD" );
3034
31- private static String dbPath ;
32- private static byte [] ownerAddr = Hex . decode ( "410000000000000000000000000000000000000000" ) ;
33- private static byte [] contractAddr = Hex . decode ( "41000000000000000000000000000000000000dEaD" );
34- private static TronApplicationContext context ;
35+ @ Resource
36+ private FullNodeHttpApiService httpApiService ;
37+ @ Resource
38+ private Application appT ;
3539
3640 @ BeforeClass
3741 public static void init () throws Exception {
@@ -43,13 +47,10 @@ public static void init() throws Exception {
4347 // build app context
4448 DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory ();
4549 beanFactory .setAllowCircularReferences (false );
46- context = new TronApplicationContext (beanFactory );
47- context .register (DefaultConfig .class );
48- context .refresh ();
49- Application appT = ApplicationFactory .create (context );
50+ }
5051
51- // register http service
52- FullNodeHttpApiService httpApiService = context . getBean ( FullNodeHttpApiService . class );
52+ @ Before
53+ public void before () {
5354 appT .addService (httpApiService );
5455
5556 // start services
@@ -71,17 +72,10 @@ public static void init() throws Exception {
7172 rootRepository .commit ();
7273 }
7374
74- @ AfterClass
75- public static void destroy () {
76- Args .clearParam ();
77- context .destroy ();
78- FileUtil .deleteDir (new File (dbPath ));
79- }
80-
8175
8276 @ Test
83- public void testNormalCall () throws Exception {
84- HttpMethed .waitToProduceOneBlock ("127.0.0.1:8090" );
77+ public void testNormalCall () {
78+ HttpMethed .waitToProduceOneBlock (httpNode );
8579 JsonObject parameter = new JsonObject ();
8680 parameter .addProperty ("owner_address" , ByteArray .toHexString (ownerAddr ));
8781 parameter .addProperty ("contract_address" , ByteArray .toHexString (contractAddr ));
@@ -94,7 +88,7 @@ public void testNormalCall() throws Exception {
9488 public static HttpResponse invokeToLocal (
9589 String method , JsonObject parameter ) {
9690 try {
97- final String requestUrl = "http://127.0.0.1:8090 /wallet/" + method ;
91+ final String requestUrl = "http://" + httpNode + " /wallet/" + method ;
9892 return HttpMethed .createConnect (requestUrl , parameter );
9993 } catch (Exception e ) {
10094 e .printStackTrace ();
0 commit comments