1616import org .tron .common .utils .FileUtil ;
1717import org .tron .core .Constant ;
1818import org .tron .core .Wallet ;
19+ import org .tron .core .capsule .AccountCapsule ;
1920import org .tron .core .capsule .TransactionResultCapsule ;
2021import org .tron .core .capsule .WitnessCapsule ;
2122import org .tron .core .config .DefaultConfig ;
2425import org .tron .core .exception .ContractExeException ;
2526import org .tron .core .exception .ContractValidateException ;
2627import org .tron .protos .Contract ;
28+ import org .tron .protos .Protocol ;
2729import org .tron .protos .Protocol .Transaction .Result .code ;
2830
2931@ Slf4j
@@ -33,7 +35,10 @@ public class WitnessUpdateActuatorTest {
3335 private static Manager dbManager ;
3436 private static final String dbPath = "output_WitnessUpdate_test" ;
3537 private static final String OWNER_ADDRESS ;
36- private static final String OWNER_ADDRESS_NOTEXIT ;
38+ private static final String OWNER_ADDRESS_ACCOUNT_NAME = "test_account" ;
39+ private static final String OWNER_ADDRESS_NOT_WITNESS ;
40+ private static final String OWNER_ADDRESS_NOT_WITNESS_ACCOUNT_NAME = "test_account1" ;
41+ private static final String OWNER_ADDRESS_NOTEXIST ;
3742 private static final String URL = "https://tron.network" ;
3843 private static final String NewURL = "https://tron.org" ;
3944 private static final String OWNER_ADDRESS_INVALIATE = "aaaa" ;
@@ -42,8 +47,10 @@ public class WitnessUpdateActuatorTest {
4247 Args .setParam (new String []{"--output-directory" , dbPath }, Constant .TEST_CONF );
4348 context = new AnnotationConfigApplicationContext (DefaultConfig .class );
4449 OWNER_ADDRESS = Wallet .getAddressPreFixString () + "abd4b9367799eaa3197fecb144eb71de1e049abc" ;
45- OWNER_ADDRESS_NOTEXIT =
50+ OWNER_ADDRESS_NOTEXIST =
4651 Wallet .getAddressPreFixString () + "548794500882809695a8a687866e76d4271a1abc" ;
52+ OWNER_ADDRESS_NOT_WITNESS =
53+ Wallet .getAddressPreFixString () + "548794500882809695a8a687866e76d427122222" ;
4754 }
4855
4956 /**
@@ -59,11 +66,28 @@ public static void init() {
5966 */
6067 @ Before
6168 public void createCapsule () {
69+ // address in accountStore and witnessStore
70+ AccountCapsule accountCapsule =
71+ new AccountCapsule (
72+ ByteString .copyFrom (ByteArray .fromHexString (OWNER_ADDRESS )),
73+ ByteString .copyFromUtf8 (OWNER_ADDRESS_ACCOUNT_NAME ),
74+ Protocol .AccountType .Normal );
75+ dbManager .getAccountStore ().put (ByteArray .fromHexString (OWNER_ADDRESS ), accountCapsule );
6276 WitnessCapsule ownerCapsule = new WitnessCapsule (
6377 ByteString .copyFrom (ByteArray .fromHexString (OWNER_ADDRESS )), 10_000_000L , URL );
64-
6578 dbManager .getWitnessStore ().put (ByteArray .fromHexString (OWNER_ADDRESS ), ownerCapsule );
66- dbManager .getWitnessStore ().delete (ByteArray .fromHexString (OWNER_ADDRESS_NOTEXIT ));
79+
80+ // address exist in accountStore, but is not witness
81+ AccountCapsule accountNotWitnessCapsule =
82+ new AccountCapsule (
83+ ByteString .copyFrom (ByteArray .fromHexString (OWNER_ADDRESS_NOT_WITNESS )),
84+ ByteString .copyFromUtf8 (OWNER_ADDRESS_NOT_WITNESS_ACCOUNT_NAME ),
85+ Protocol .AccountType .Normal );
86+ dbManager .getAccountStore ().put (ByteArray .fromHexString (OWNER_ADDRESS_NOT_WITNESS ), accountNotWitnessCapsule );
87+ dbManager .getWitnessStore ().delete (ByteArray .fromHexString (OWNER_ADDRESS_NOT_WITNESS ));
88+
89+ // address does not exist in accountStore
90+ dbManager .getAccountStore ().delete (ByteArray .fromHexString (OWNER_ADDRESS_NOTEXIST ));
6791 }
6892
6993 private Any getContract (String address , String url ) {
@@ -197,21 +221,41 @@ public void invalidateUrlTest() {
197221 }
198222
199223 /**
200- * use AccountStore not exists Address createWitness,result is failed,exception is "account not
201- * exists".
224+ * use AccountStore not exists Address createWitness,result is failed,exception is
225+ * "Witness does not exist"
226+ */
227+ @ Test
228+ public void notExistWitness () {
229+ WitnessUpdateActuator actuator = new WitnessUpdateActuator (
230+ getContract (OWNER_ADDRESS_NOT_WITNESS , URL ), dbManager );
231+ TransactionResultCapsule ret = new TransactionResultCapsule ();
232+ try {
233+ actuator .validate ();
234+ actuator .execute (ret );
235+ fail ("witness [+OWNER_ADDRESS_NOACCOUNT+] not exists" );
236+ } catch (ContractValidateException e ) {
237+ Assert .assertTrue (e instanceof ContractValidateException );
238+ Assert .assertEquals ("Witness does not exist" , e .getMessage ());
239+ } catch (ContractExeException e ) {
240+ Assert .assertFalse (e instanceof ContractExeException );
241+ }
242+ }
243+
244+ /**
245+ * if account does not exist in accountStore, the test will throw a Exception
202246 */
203247 @ Test
204- public void notExitWitness () {
248+ public void notExistAccount () {
205249 WitnessUpdateActuator actuator = new WitnessUpdateActuator (
206- getContract (OWNER_ADDRESS_NOTEXIT , URL ), dbManager );
250+ getContract (OWNER_ADDRESS_NOTEXIST , URL ), dbManager );
207251 TransactionResultCapsule ret = new TransactionResultCapsule ();
208252 try {
209253 actuator .validate ();
210254 actuator .execute (ret );
211- fail ("account[+OWNER_ADDRESS_NOACCOUNT+] not exists " );
255+ fail ("account does not exist " );
212256 } catch (ContractValidateException e ) {
213257 Assert .assertTrue (e instanceof ContractValidateException );
214- Assert .assertEquals ("Witness not existed " , e .getMessage ());
258+ Assert .assertEquals ("account does not exist " , e .getMessage ());
215259 } catch (ContractExeException e ) {
216260 Assert .assertFalse (e instanceof ContractExeException );
217261 }
0 commit comments