[Testing staking_verifier] Fix the error of CV5 ~ CV8 (#2377)

* Fix the error of CV5 ~ CV8

* Use ctxerror to rebuild unit test: CV5 ~ CV8
pull/2379/head
Edgar Aroutiounian 5 years ago committed by GitHub
parent a53d8d31d5
commit 51b3e1ba8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 66
      core/staking_verifier_test.go

@ -100,12 +100,20 @@ func TestCV3(t *testing.T) {
func TestCV5(t *testing.T) {
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
msg := createValidator()
statedb.AddBalance(msg.ValidatorAddress, big.NewInt(5e18))
// identity length: 200 characters
msg.Identity = "adsfwryuiwfhwifbwfbcerghveugbviuscbhwiefbcusidbcifwefhgciwefherhbfiwuehfciwiuebfcuyiewfhwieufwiweifhcwefhwefhwiewwerfhuwefiuewfhuewhfiuewhfefhshfrhfhifhwbfvberhbvihfwuoefhusioehfeuwiafhaiobcfwfhceirui"
statedb.AddBalance(msg.ValidatorAddress, big.NewInt(5e18))
identitylengthError := ctxerror.New("[EnsureLength] Exceed Maximum Length", "have", len(msg.Identity), "maxIdentityLen", staking.MaxIdentityLength)
if _, err := VerifyAndCreateValidatorFromMsg(statedb, big.NewInt(0), big.NewInt(0), msg); err.Error() != identitylengthError.Error() {
t.Error("expected", identitylengthError, "got", err)
identitylengthCtxError := ctxerror.New("[EnsureLength] Exceed Maximum Length", "have", len(msg.Identity), "maxIdentityLen", staking.MaxIdentityLength)
_, err := VerifyAndCreateValidatorFromMsg(statedb, big.NewInt(0), big.NewInt(0), msg)
if err == nil {
t.Errorf("expected non null error")
}
ctxerr, ok := err.(ctxerror.CtxError)
if !ok {
t.Errorf("expected context aware error")
}
if ctxerr.Message() != identitylengthCtxError.Message() {
t.Error("expected", identitylengthCtxError, "got", err)
}
}
@ -113,12 +121,20 @@ func TestCV5(t *testing.T) {
func TestCV6(t *testing.T) {
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
msg := createValidator()
statedb.AddBalance(msg.ValidatorAddress, big.NewInt(5e18))
// Website length: 200 characters
msg.Website = "https://www.iwfhwifbwfbcerghveugbviuscbhwiefbcusidbcifwefhgciwefherhbfiwuehfciwiuebfcuyiewfhwieufwiweifhcwefhwefhwiewwerfhuwefiuewfwwwwwfiuewhfefhshfrheterhbvihfwuoefhusioehfeuwiafhaiobcfwfhceirui.com"
statedb.AddBalance(msg.ValidatorAddress, big.NewInt(5e18))
websiteLengthError := ctxerror.New("[EnsureLength] Exceed Maximum Length", "have", len(msg.Website), "maxWebsiteLen", staking.MaxWebsiteLength)
if _, err := VerifyAndCreateValidatorFromMsg(statedb, big.NewInt(0), big.NewInt(0), msg); err.Error() != websiteLengthError.Error() {
t.Error("expected", websiteLengthError, "got", err)
websiteLengthCtxError := ctxerror.New("[EnsureLength] Exceed Maximum Length", "have", len(msg.Website), "maxWebsiteLen", staking.MaxWebsiteLength)
_, err := VerifyAndCreateValidatorFromMsg(statedb, big.NewInt(0), big.NewInt(0), msg)
if err == nil {
t.Errorf("expected non null error")
}
ctxerr, ok := err.(ctxerror.CtxError)
if !ok {
t.Errorf("expected context aware error")
}
if ctxerr.Message() != websiteLengthCtxError.Message() {
t.Error("expected", websiteLengthCtxError, "got", err)
}
}
@ -126,11 +142,19 @@ func TestCV6(t *testing.T) {
func TestCV7(t *testing.T) {
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
msg := createValidator()
// Website length: 200 characters
msg.SecurityContact = "HelloiwfhwifbwfbcerghveugbviuscbhwiefbcusidbcifwefhgciwefherhbfiwuehfciwiuebfcuyiewfhwieufwiweifhcwefhwefhwiewwerfhuwefiuewfwwwwwfiuewhfefhshfrheterhbvihfwuoefhusioehfeuwiafhaiobcfwfhceiruiHellodfdfdf"
statedb.AddBalance(msg.ValidatorAddress, big.NewInt(5e18))
securityContactLengthError := ctxerror.New("[EnsureLength] Exceed Maximum Length", "have", len(msg.SecurityContact), "maxSecurityContactLen", staking.MaxWebsiteLength)
if _, err := VerifyAndCreateValidatorFromMsg(statedb, big.NewInt(0), big.NewInt(0), msg); err.Error() != securityContactLengthError.Error() {
// Security Contact length: 200 characters
msg.SecurityContact = "HelloiwfhwifbwfbcerghveugbviuscbhwiefbcusidbcifwefhgciwefherhbfiwuehfciwiuebfcuyiewfhwieufwiweifhcwefhwefhwiewwerfhuwefiuewfwwwwwfiuewhfefhshfrheterhbvihfwuoefhusioehfeuwiafhaiobcfwfhceiruiHellodfdfdf"
securityContactLengthError := ctxerror.New("[EnsureLength] Exceed Maximum Length", "have", len(msg.SecurityContact), "maxSecurityContactLen", staking.MaxSecurityContactLength)
_, err := VerifyAndCreateValidatorFromMsg(statedb, big.NewInt(0), big.NewInt(0), msg)
if err == nil {
t.Errorf("expected non null error")
}
ctxerr, ok := err.(ctxerror.CtxError)
if !ok {
t.Errorf("expected context aware error")
}
if ctxerr.Message() != securityContactLengthError.Message() {
t.Error("expected", securityContactLengthError, "got", err)
}
}
@ -139,12 +163,20 @@ func TestCV7(t *testing.T) {
func TestCV8(t *testing.T) {
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
msg := createValidator()
// Website length: 300 characters
msg.Details = "HelloiwfhwifbwfbcerghveugbviuscbhwiefbcusidbcifwefhgciwefherhbfiwuehfciwiuebfcuyiewfhwieufwiweifhcwefhwefhwiewwerfhuwefiuewfwwwwwfiuewhfefhshfrheterhbvihfwuoefhusioehfeuwiafhaiobcfwfhceiruiHellodfdfdfjiusngognoherugbounviesrbgufhuoshcofwevusguahferhgvuervurehniwjvseivusehvsghjvorsugjvsiovjpsevsvvvvv"
statedb.AddBalance(msg.ValidatorAddress, big.NewInt(5e18))
detailsLenError := ctxerror.New("[EnsureLength] Exceed Maximum Length", "have", len(msg.Details), "maxDetailsLen", staking.MaxDetailsLength)
if _, err := VerifyAndCreateValidatorFromMsg(statedb, big.NewInt(0), big.NewInt(0), msg); err.Error() != detailsLenError.Error() {
t.Error("expected", detailsLenError, "got", err)
// Details length: 300 characters
msg.Details = "HelloiwfhwifbwfbcerghveugbviuscbhwiefbcusidbcifwefhgciwefherhbfiwuehfciwiuebfcuyiewfhwieufwiweifhcwefhwefhwiewwerfhuwefiuewfwwwwwfiuewhfefhshfrheterhbvihfwuoefhusioehfeuwiafhaiobcfwfhceiruiHellodfdfdfjiusngognoherugbounviesrbgufhuoshcofwevusguahferhgvuervurehniwjvseivusehvsghjvorsugjvsiovjpsevsvvvvv"
detailsLenCtxError := ctxerror.New("[EnsureLength] Exceed Maximum Length", "have", len(msg.Details), "maxDetailsLen", staking.MaxDetailsLength)
_, err := VerifyAndCreateValidatorFromMsg(statedb, big.NewInt(0), big.NewInt(0), msg)
if err == nil {
t.Errorf("Expected non null error")
}
ctxerr, ok := err.(ctxerror.CtxError)
if !ok {
t.Errorf("expected context aware error")
}
if ctxerr.Message() != detailsLenCtxError.Message() {
t.Error("expected", detailsLenCtxError, "got", err)
}
}

Loading…
Cancel
Save