From 35b6df37fb64177653f0ca57fd964d37e438f917 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orkun=20K=C3=BCl=C3=A7e?= Date: Mon, 6 Apr 2020 20:15:24 +0300 Subject: [PATCH] Non owner can delete domain after grace period ends (#1201) * bnsd: Implement grace perion feature on deleteDomain * bnscli: add domain grace period to update-account-conf * bnsd: Add domain grace period to datamigration * Add changelog --- CHANGELOG.md | 1 + .../account_update_configuration.test.gold | 3 +- cmd/bnscli/cmd_account.go | 4 +- cmd/bnsd/app/datamigration.go | 2 + cmd/bnsd/x/account/codec.pb.go | 168 +++++++++++------- cmd/bnsd/x/account/codec.proto | 5 +- cmd/bnsd/x/account/handler.go | 17 +- cmd/bnsd/x/account/handler_test.go | 63 +++++++ 8 files changed, 194 insertions(+), 69 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b827469..218b8260 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## HEAD +- `feature/account`: A non owner can delete domain after grace period ends ## 1.0.1 - `bnsd`: updated error messages to better reflect the account module spec diff --git a/cmd/bnscli/clitests/account_update_configuration.test.gold b/cmd/bnscli/clitests/account_update_configuration.test.gold index 6df036da..a6d8cf63 100644 --- a/cmd/bnscli/clitests/account_update_configuration.test.gold +++ b/cmd/bnscli/clitests/account_update_configuration.test.gold @@ -13,7 +13,8 @@ "valid_name": "^valid-name-rule$", "valid_blockchain_id": "^valid-bl-id-rule$", "valid_blockchain_address": "^valid-bl-address-rule$", - "domain_renew": 151711200 + "domain_renew": 151711200, + "domain_grace_period": 2592000 } } } diff --git a/cmd/bnscli/cmd_account.go b/cmd/bnscli/cmd_account.go index 8cf5da61..a0cf2ceb 100644 --- a/cmd/bnscli/cmd_account.go +++ b/cmd/bnscli/cmd_account.go @@ -115,7 +115,7 @@ Create a transaction for registering an account within a given domain. nameFl = fl.String("name", "", "Account name") domainFl = fl.String("domain", "", "Account domain.") adminFl = flAddress(fl, "owner", "", "An address that the newly registered account will belong to.") - brokerFl = flAddress(fl, "broker", "", "Address of the issuer entity") + brokerFl = flAddress(fl, "broker", "", "Address of the issuer entity") ) fl.Parse(args) @@ -201,6 +201,7 @@ Create a transaction to change account extension configuration. validBlockchainID = fl.String("valid-bl-id", "", "Regular expression defining a rule for a valid blockchain ID string.") validBlockchainAddr = fl.String("valid-bl-address", "", "Regular expression defining a rule for a valid blockchain address string.") domainRenewFl = fl.Duration("domain-renew", 0, "Domain renew time.") + domainGracePeriodFl = fl.Duration("domain-grace-period", 30*24*time.Hour, "Domain grace period.") ) fl.Parse(args) @@ -214,6 +215,7 @@ Create a transaction to change account extension configuration. ValidBlockchainID: *validBlockchainID, ValidBlockchainAddress: *validBlockchainAddr, DomainRenew: weave.AsUnixDuration(*domainRenewFl), + DomainGracePeriod: weave.AsUnixDuration(*domainGracePeriodFl), }, } if err := msg.Validate(); err != nil { diff --git a/cmd/bnsd/app/datamigration.go b/cmd/bnsd/app/datamigration.go index ef95a5de..4e4f81dc 100644 --- a/cmd/bnsd/app/datamigration.go +++ b/cmd/bnsd/app/datamigration.go @@ -65,6 +65,7 @@ func migrateRelease_1_0(ctx context.Context, db weave.KVStore) error { ValidBlockchainID: `^[a-z0-9A-Z\-]+$`, ValidBlockchainAddress: `^[a-z0-9A-Z]+$`, DomainRenew: weave.AsUnixDuration(365*24*time.Hour + 6*time.Hour), + DomainGracePeriod: weave.AsUnixDuration(30 * 24 * time.Hour), }); err != nil { return errors.Wrap(err, "save initial gconf configuration") } @@ -85,6 +86,7 @@ func migrateRelease_1_0(ctx context.Context, db weave.KVStore) error { ValidBlockchainID: `^[a-z0-9A-Z\-:]+$`, ValidBlockchainAddress: `^[a-z0-9A-Z]+$`, DomainRenew: weave.AsUnixDuration(365*24*time.Hour + 6*time.Hour), + DomainGracePeriod: weave.AsUnixDuration(30 * 24 * time.Hour), }); err != nil { return errors.Wrap(err, "save final gconf configuration") } diff --git a/cmd/bnsd/x/account/codec.pb.go b/cmd/bnsd/x/account/codec.pb.go index 580f4126..ed4d5400 100644 --- a/cmd/bnsd/x/account/codec.pb.go +++ b/cmd/bnsd/x/account/codec.pb.go @@ -5,13 +5,14 @@ package account import ( fmt "fmt" + io "io" + math "math" + _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" github_com_iov_one_weave "github.com/iov-one/weave" weave "github.com/iov-one/weave" coin "github.com/iov-one/weave/coin" - io "io" - math "math" ) // Reference imports to suppress errors if they are not otherwise used. @@ -410,8 +411,11 @@ type Configuration struct { // Valid blockchain address defines a regular expression that a valid target // blockchain address must match. ValidBlockchainAddress string `protobuf:"bytes,6,opt,name=valid_blockchain_address,json=validBlockchainAddress,proto3" json:"valid_blockchain_address,omitempty"` - // Domain review defines the duration of the domain renewal period. + // Domain renew defines the duration of the domain renewal period. DomainRenew github_com_iov_one_weave.UnixDuration `protobuf:"varint,7,opt,name=domain_renew,json=domainRenew,proto3,casttype=github.com/iov-one/weave.UnixDuration" json:"domain_renew,omitempty"` + // Domain grace period defines the duration of the release duration of a domain. A non-admin + // can delete the domain after the grace period ends. + DomainGracePeriod github_com_iov_one_weave.UnixDuration `protobuf:"varint,8,opt,name=domain_grace_period,json=domainGracePeriod,proto3,casttype=github.com/iov-one/weave.UnixDuration" json:"domain_grace_period,omitempty"` } func (m *Configuration) Reset() { *m = Configuration{} } @@ -496,6 +500,13 @@ func (m *Configuration) GetDomainRenew() github_com_iov_one_weave.UnixDuration { return 0 } +func (m *Configuration) GetDomainGracePeriod() github_com_iov_one_weave.UnixDuration { + if m != nil { + return m.DomainGracePeriod + } + return 0 +} + // UpdateConfigurationMsg is used by the gconf extension to update the // configuration. type UpdateConfigurationMsg struct { @@ -1486,67 +1497,69 @@ func init() { func init() { proto.RegisterFile("cmd/bnsd/x/account/codec.proto", fileDescriptor_8f0cd3fcad09e620) } var fileDescriptor_8f0cd3fcad09e620 = []byte{ - // 959 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x57, 0xcf, 0x6f, 0xe3, 0x44, - 0x14, 0xae, 0x9b, 0xdf, 0x2f, 0x0e, 0x6d, 0x06, 0xa8, 0x4c, 0x11, 0x89, 0xd7, 0xb0, 0x52, 0x56, - 0x40, 0x22, 0x15, 0x21, 0xd0, 0x0a, 0x21, 0x25, 0x2d, 0x15, 0x2b, 0xd1, 0x82, 0x4c, 0xbb, 0xd7, - 0x68, 0x62, 0x4f, 0x6c, 0xd3, 0x78, 0x1c, 0x79, 0x26, 0xcd, 0x1e, 0x39, 0x70, 0xe1, 0xc6, 0x85, - 0x13, 0x07, 0x84, 0xf8, 0x07, 0x38, 0x71, 0xe3, 0xbe, 0xc7, 0x3d, 0x72, 0x8a, 0x50, 0xfa, 0x5f, - 0xf4, 0x84, 0x3c, 0x33, 0x69, 0xe2, 0x16, 0x10, 0xee, 0x66, 0xab, 0x3d, 0xc5, 0x7e, 0xf3, 0xde, - 0x9b, 0x6f, 0xde, 0xf7, 0xbd, 0x37, 0x0e, 0x34, 0x9c, 0xd0, 0xed, 0x0c, 0x28, 0x73, 0x3b, 0x4f, - 0x3a, 0xd8, 0x71, 0xa2, 0x09, 0xe5, 0x1d, 0x27, 0x72, 0x89, 0xd3, 0x1e, 0xc7, 0x11, 0x8f, 0x50, - 0x49, 0x19, 0x77, 0xab, 0x2b, 0xd6, 0xdd, 0x6d, 0x27, 0x0a, 0xe8, 0xaa, 0xdf, 0xee, 0x6b, 0x5e, - 0xe4, 0x45, 0xe2, 0xb1, 0x93, 0x3c, 0x49, 0xab, 0xf5, 0x47, 0x0e, 0x8a, 0x07, 0x51, 0x88, 0x03, - 0x8a, 0xde, 0x85, 0x72, 0x48, 0x38, 0x76, 0x31, 0xc7, 0x86, 0x66, 0x6a, 0xad, 0xea, 0xde, 0x56, - 0x7b, 0x4a, 0xf0, 0x39, 0x69, 0x1f, 0x29, 0xb3, 0x7d, 0xe5, 0x80, 0x76, 0xa0, 0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xfa, 0x04, 0x8a, 0x83, 0x38, 0x3a, 0x23, 0xb1, 0x51, 0xce, 0x50, 0x32, 0x15, - 0x63, 0x1d, 0x43, 0x2d, 0x85, 0x16, 0xbd, 0x21, 0xcf, 0x35, 0xc6, 0xdc, 0x17, 0x2c, 0x56, 0x04, - 0xf2, 0xaf, 0x30, 0xf7, 0x91, 0x05, 0xb9, 0x21, 0x21, 0x82, 0xb0, 0xea, 0x1e, 0xb4, 0x13, 0x85, - 0xb4, 0xf7, 0xa3, 0x80, 0xaa, 0x13, 0x26, 0x8b, 0xd6, 0x77, 0x39, 0x28, 0xa9, 0x84, 0xeb, 0x11, - 0x04, 0x82, 0x3c, 0xc5, 0x21, 0x11, 0x7a, 0xa8, 0xd8, 0xe2, 0x39, 0x11, 0x49, 0x34, 0xa5, 0x24, - 0x16, 0x14, 0xff, 0x6f, 0x91, 0x88, 0x90, 0xeb, 0x22, 0x29, 0xdc, 0x56, 0x24, 0x0f, 0xa1, 0xc4, - 0x71, 0xec, 0x11, 0xbe, 0xa0, 0x7f, 0xf7, 0x8a, 0xfe, 0xde, 0x28, 0x72, 0xce, 0x1c, 0x1f, 0x07, - 0x54, 0xed, 0xbd, 0x90, 0x80, 0x0a, 0x40, 0x16, 0xe8, 0x0e, 0x89, 0x79, 0x30, 0x0c, 0x1c, 0xcc, - 0x09, 0x33, 0x4a, 0x66, 0xae, 0xa5, 0xdb, 0x29, 0xdb, 0x73, 0xd2, 0xea, 0x42, 0xfd, 0x06, 0x0a, - 0xf4, 0x21, 0xd4, 0x06, 0x57, 0xc6, 0x7e, 0xe0, 0x4a, 0x7e, 0x7b, 0xdb, 0xf3, 0x59, 0x53, 0x5f, - 0x7a, 0x3f, 0x3a, 0xb0, 0xf5, 0xa5, 0xdb, 0x23, 0x17, 0x19, 0x50, 0xc2, 0x32, 0x83, 0xa2, 0x66, - 0xf1, 0x6a, 0x7d, 0x9f, 0x83, 0xda, 0x7e, 0x44, 0x87, 0x81, 0xa7, 0xa4, 0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 0xf6, 0x6c, 0xde, 0xd0, 0xfe, 0x9a, 0x37, 0xb4, 0x1f, - 0x2e, 0x1a, 0x1b, 0xcf, 0x2e, 0x1a, 0x1b, 0x7f, 0x5e, 0x34, 0x36, 0x06, 0x45, 0xf1, 0x77, 0xf4, - 0x83, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0xd3, 0x5c, 0xcd, 0x6c, 0xee, 0x0e, 0x00, 0x00, + // 988 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x57, 0x4f, 0x6f, 0xe3, 0x44, + 0x14, 0xaf, 0x9b, 0x7f, 0xcd, 0x8b, 0x43, 0x1b, 0x2f, 0x54, 0xa6, 0x88, 0x24, 0x6b, 0x58, 0x29, + 0x2b, 0x20, 0x91, 0x8a, 0x10, 0x68, 0x85, 0x90, 0x92, 0x96, 0xc2, 0x4a, 0xb4, 0xac, 0x4c, 0xbb, + 0x12, 0xa7, 0x68, 0x62, 0xbf, 0xd8, 0xa6, 0xc9, 0x4c, 0xe4, 0x71, 0x9a, 0x3d, 0x72, 0xe0, 0x03, + 0x70, 0xe1, 0xc4, 0x01, 0x21, 0xbe, 0x00, 0x27, 0x6e, 0xdc, 0xf7, 0xb8, 0x47, 0x4e, 0x11, 0x4a, + 0xf9, 0x14, 0x3d, 0x21, 0xcf, 0x4c, 0x9a, 0xb8, 0x05, 0x84, 0xbb, 0xd9, 0x6a, 0x4f, 0xb1, 0xdf, + 0xbc, 0xf7, 0xe6, 0x37, 0xef, 0xf7, 0x7b, 0xf3, 0x1c, 0xa8, 0x3a, 0x43, 0xb7, 0xd5, 0xa3, 0xdc, + 0x6d, 0x3d, 0x69, 0x11, 0xc7, 0x61, 0x63, 0x1a, 0xb5, 0x1c, 0xe6, 0xa2, 0xd3, 0x1c, 0x85, 0x2c, + 0x62, 0x46, 0x41, 0x19, 0x77, 0x4a, 0x4b, 0xd6, 0x9d, 0x2d, 0x87, 0x05, 0x74, 0xd9, 0x6f, 0xe7, + 0x55, 0x8f, 0x79, 0x4c, 0x3c, 0xb6, 0xe2, 0x27, 0x69, 0xb5, 0x7e, 0xcf, 0x40, 0x7e, 0x9f, 0x0d, + 0x49, 0x40, 0x8d, 0x77, 0x60, 0x63, 0x88, 0x11, 0x71, 0x49, 0x44, 0x4c, 0xad, 0xae, 0x35, 0x4a, + 0xbb, 0x9b, 0xcd, 0x09, 0x92, 0x33, 0x6c, 0x1e, 0x2a, 0xb3, 0x7d, 0xe9, 0x60, 0x6c, 0x43, 0xde, + 0x15, 0x61, 0xe6, 0x7a, 0x5d, 0x6b, 0x14, 0x6d, 0xf5, 0x66, 0x3c, 0x80, 0x1c, 0x71, 0x87, 0x01, + 0x35, 0x33, 0x75, 0xad, 0xa1, 0x77, 0xde, 0xbe, 0x98, 0xd6, 0xea, 0x5e, 0x10, 0xf9, 0xe3, 0x5e, + 0xd3, 0x61, 0xc3, 0x56, 0xc0, 0xce, 0xde, 0x63, 0x14, 0x5b, 0x32, 0x6f, 0xdb, 0x75, 0x43, 0xe4, + 0xdc, 0x96, 0x21, 0xc6, 0x01, 0x94, 0xce, 0xc8, 0x20, 0x70, 0xbb, 0x63, 0x1a, 0x05, 0x03, 0x33, + 0x5b, 0xd7, 0x1a, 0x99, 0xce, 0xbd, 0x8b, 0x69, 0xed, 0xee, 0xbf, 0x66, 0x38, 0xa1, 0xc1, 0x93, + 0xe3, 0x60, 0x88, 0x36, 0x88, 0xc8, 0x93, 0x38, 0xd0, 0x78, 0x0b, 0xca, 0x3e, 0xe1, 0x5d, 0x3e, + 0x1e, 0x61, 0x38, 0xe6, 0x18, 0x9a, 0xb9, 0xba, 0xd6, 0xd8, 0xb0, 0x75, 0x9f, 0xf0, 0xaf, 0xe6, + 0x36, 0xe3, 0x43, 0xd8, 0x18, 0x72, 0xaf, 0xdb, 0x47, 0xe4, 0x66, 0xbe, 0x9e, 0x69, 0x94, 0x76, + 0xb7, 0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x78, 0xd6, 0x29, 0x6c, 0x49, 0xa5, 0xdf, 0x42, 0xa1, 0xe3, 0x6e, 0x3d, 0x18, + 0x8c, 0xb9, 0xbf, 0xe2, 0xae, 0xfa, 0x06, 0x36, 0xc5, 0x25, 0x70, 0x1b, 0x47, 0xf8, 0x41, 0x03, + 0xb3, 0xed, 0xba, 0x6a, 0xab, 0xbd, 0xc5, 0xe7, 0xe4, 0x0b, 0x55, 0x68, 0x1d, 0x4a, 0x4b, 0x5f, + 0xae, 0x52, 0xa3, 0xf6, 0xb2, 0xc9, 0xfa, 0x59, 0x83, 0x37, 0x12, 0x44, 0xde, 0x16, 0xb4, 0xfb, + 0xb0, 0xb5, 0x84, 0xa3, 0xeb, 0x13, 0xee, 0x2b, 0x7c, 0x9b, 0x4b, 0xf6, 0xcf, 0x09, 0xf7, 0x3b, + 0xe6, 0xd3, 0x59, 0x55, 0x7b, 0x36, 0xab, 0x6a, 0x7f, 0xce, 0xaa, 0xda, 0xf7, 0xe7, 0xd5, 0xb5, + 0x67, 0xe7, 0xd5, 0xb5, 0x3f, 0xce, 0xab, 0x6b, 0xbd, 0xbc, 0xf8, 0xa7, 0xfb, 0xfe, 0xdf, 0x01, + 0x00, 0x00, 0xff, 0xff, 0xb0, 0x9c, 0x48, 0xd9, 0x49, 0x0f, 0x00, 0x00, } func (m *Domain) Marshal() (dAtA []byte, err error) { @@ -1826,6 +1839,11 @@ func (m *Configuration) MarshalTo(dAtA []byte) (int, error) { i++ i = encodeVarintCodec(dAtA, i, uint64(m.DomainRenew)) } + if m.DomainGracePeriod != 0 { + dAtA[i] = 0x40 + i++ + i = encodeVarintCodec(dAtA, i, uint64(m.DomainGracePeriod)) + } return i, nil } @@ -2620,6 +2638,9 @@ func (m *Configuration) Size() (n int) { if m.DomainRenew != 0 { n += 1 + sovCodec(uint64(m.DomainRenew)) } + if m.DomainGracePeriod != 0 { + n += 1 + sovCodec(uint64(m.DomainGracePeriod)) + } return n } @@ -4032,6 +4053,25 @@ func (m *Configuration) Unmarshal(dAtA []byte) error { break } } + case 8: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DomainGracePeriod", wireType) + } + m.DomainGracePeriod = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCodec + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DomainGracePeriod |= github_com_iov_one_weave.UnixDuration(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipCodec(dAtA[iNdEx:]) diff --git a/cmd/bnsd/x/account/codec.proto b/cmd/bnsd/x/account/codec.proto index 691a3447..21315fa2 100644 --- a/cmd/bnsd/x/account/codec.proto +++ b/cmd/bnsd/x/account/codec.proto @@ -119,8 +119,11 @@ message Configuration { // Valid blockchain address defines a regular expression that a valid target // blockchain address must match. string valid_blockchain_address = 6; - // Domain review defines the duration of the domain renewal period. + // Domain renew defines the duration of the domain renewal period. int64 domain_renew = 7 [(gogoproto.casttype) = "github.com/iov-one/weave.UnixDuration"]; + // Domain grace period defines the duration of the release duration of a domain. A non-admin + // can delete the domain after the grace period ends. + int64 domain_grace_period = 8 [(gogoproto.casttype) = "github.com/iov-one/weave.UnixDuration"]; } // UpdateConfigurationMsg is used by the gconf extension to update the diff --git a/cmd/bnsd/x/account/handler.go b/cmd/bnsd/x/account/handler.go index 5b68eb70..beac2ed3 100644 --- a/cmd/bnsd/x/account/handler.go +++ b/cmd/bnsd/x/account/handler.go @@ -489,9 +489,22 @@ func (h *deleteDomainHandler) validate(ctx weave.Context, db weave.KVStore, tx w if !domain.HasSuperuser { return nil, nil, errors.Wrap(errors.ErrState, "domain without a superuser cannot be deleted") } - if !h.auth.HasAddress(ctx, domain.Admin) { - return nil, nil, errors.Wrap(errors.ErrUnauthorized, "only admin can delete a domain") + conf, err := loadConf(db) + if err != nil { + return nil, nil, errors.Wrap(err, "cannot load configuration") } + now, err := weave.BlockTime(ctx) + if err != nil { + return nil, nil, errors.Wrap(err, "block time") + } + // if now > domain.ValidUntil + DomainGracePeriod then non owner can delete + // issue https://github.com/iov-one/weave/issues/1199 + if !now.After(domain.ValidUntil.Add(conf.DomainGracePeriod.Duration()).Time()) { + if !h.auth.HasAddress(ctx, domain.Admin) { + return nil, nil, errors.Wrap(errors.ErrUnauthorized, "only admin can delete a domain") + } + } + return &domain, &msg, nil } diff --git a/cmd/bnsd/x/account/handler_test.go b/cmd/bnsd/x/account/handler_test.go index 9ef094e4..62dfe876 100644 --- a/cmd/bnsd/x/account/handler_test.go +++ b/cmd/bnsd/x/account/handler_test.go @@ -2435,6 +2435,68 @@ func TestUseCases(t *testing.T) { } }, }, + "a domain cannot be deleted by a non owner between valid until and grace period": { + Requests: []Request{ + { + Now: now, + Conditions: []weave.Condition{aliceCond}, + Tx: &weavetest.Tx{ + Msg: &RegisterDomainMsg{ + Metadata: &weave.Metadata{Schema: 1}, + Domain: "wunderland", + Admin: aliceCond.Address(), + HasSuperuser: true, + AccountRenew: 1000, + }, + }, + BlockHeight: 100, + WantErr: nil, + }, + { + Now: now + 1010, // now + valid until = 1010 < + Conditions: []weave.Condition{bobCond}, + Tx: &weavetest.Tx{ + Msg: &DeleteDomainMsg{ + Metadata: &weave.Metadata{Schema: 1}, + Domain: "wunderland", + }, + }, + BlockHeight: 101, + WantErr: errors.ErrUnauthorized, + }, + }, + }, + "a non owner can delete domain after grace period ends": { + Requests: []Request{ + { + Now: now, + Conditions: []weave.Condition{aliceCond}, + Tx: &weavetest.Tx{ + Msg: &RegisterDomainMsg{ + Metadata: &weave.Metadata{Schema: 1}, + Domain: "wunderland", + Admin: aliceCond.Address(), + HasSuperuser: true, + AccountRenew: 1000, + }, + }, + BlockHeight: 100, + WantErr: nil, + }, + { + Now: now + 1011, // now + valid + Conditions: []weave.Condition{bobCond}, + Tx: &weavetest.Tx{ + Msg: &DeleteDomainMsg{ + Metadata: &weave.Metadata{Schema: 1}, + Domain: "wunderland", + }, + }, + BlockHeight: 101, + WantErr: nil, + }, + }, + }, } for testName, tc := range cases { @@ -2454,6 +2516,7 @@ func TestUseCases(t *testing.T) { ValidBlockchainID: `^[a-z0-9]{2,64}$`, ValidBlockchainAddress: `^[a-z0-9]{3,128}$`, DomainRenew: 1000, + DomainGracePeriod: 10, } if err := gconf.Save(db, "account", &config); err != nil { t.Fatalf("cannot save configuration: %s", err)