diff --git a/CHANGELOG.md b/CHANGELOG.md index c65eed2e..736631be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## HEAD +- `bnsd`: account targets are cleared when an account is transferred - `bnsd`: domain renew expiration time equals to domain expiration time + configuration domain renew duration, if this time is before current block time then renew time becomes current block time + configuration domain renew duration - `bnsd`: revert burn feature - `bnsd`: when a domain is transferred accounts ownership is transferred to the new domain owner and accounts' targets are cleared diff --git a/cmd/bnsd/x/account/handler.go b/cmd/bnsd/x/account/handler.go index 8d296ce2..733faa17 100644 --- a/cmd/bnsd/x/account/handler.go +++ b/cmd/bnsd/x/account/handler.go @@ -594,8 +594,12 @@ func (h *transferAccountHandler) Deliver(ctx weave.Context, db weave.KVStore, tx if err != nil { return nil, err } + // set new owner account.Owner = msg.NewOwner + // reset certificates account.Certificates = nil + // reset targets + account.Targets = nil if _, err := h.accounts.Put(db, accountKey(msg.Name, msg.Domain), account); err != nil { return nil, errors.Wrap(err, "cannot store account") } diff --git a/cmd/bnsd/x/account/handler_test.go b/cmd/bnsd/x/account/handler_test.go index eb75ed13..9ef094e4 100644 --- a/cmd/bnsd/x/account/handler_test.go +++ b/cmd/bnsd/x/account/handler_test.go @@ -2234,6 +2234,105 @@ func TestUseCases(t *testing.T) { } }, }, + "when an account is transferred targets and certificates are reset": { + Requests: []Request{ + // register domain + { + Now: now, + Conditions: []weave.Condition{adminCond}, + Tx: &weavetest.Tx{ + Msg: &RegisterDomainMsg{ + Metadata: &weave.Metadata{Schema: 1}, + Domain: "wunderland", + Admin: aliceCond.Address(), + HasSuperuser: false, + AccountRenew: 1000, + }, + }, + BlockHeight: 100, + WantErr: nil, + }, + // register acc + { + Now: now + 1, + Conditions: []weave.Condition{bobCond}, + Tx: &weavetest.Tx{ + Msg: &RegisterAccountMsg{ + Metadata: &weave.Metadata{Schema: 1}, + Domain: "wunderland", + Name: "bob", + Owner: bobCond.Address(), + }, + }, + BlockHeight: 101, + WantErr: nil, + }, + // add cert + { + Now: now + 2, + Conditions: []weave.Condition{bobCond}, + Tx: &weavetest.Tx{ + Msg: &AddAccountCertificateMsg{ + Metadata: &weave.Metadata{Schema: 1}, + Domain: "wunderland", + Name: "bob", + Certificate: []byte("cert"), + }, + }, + BlockHeight: 102, + WantErr: nil, + }, + // add target + { + Now: now + 3, + Conditions: []weave.Condition{bobCond}, + Tx: &weavetest.Tx{ + Msg: &ReplaceAccountTargetsMsg{ + Metadata: &weave.Metadata{Schema: 1}, + Domain: "wunderland", + Name: "bob", + NewTargets: []BlockchainAddress{{ + BlockchainID: "some-bc-id", + Address: "some-address", + }}, + }, + Err: nil, + }, + BlockHeight: 103, + WantErr: nil, + }, + // transfer account + { + Now: now + 4, + Conditions: []weave.Condition{bobCond}, + Tx: &weavetest.Tx{ + Msg: &TransferAccountMsg{ + Metadata: &weave.Metadata{Schema: 1}, + Domain: "wunderland", + Name: "bob", + NewOwner: charlieCond.Address(), + }, + }, + BlockHeight: 104, + WantErr: nil, + }, + }, + AfterTest: func(t *testing.T, db weave.KVStore) { + accounts := NewAccountBucket() + var a Account + if err := accounts.One(db, accountKey("bob", "wunderland"), &a); err != nil { + t.Fatalf("cannot get wunderland account: %s", err) + } + // check if targets are cleared + if len(a.Targets) != 0 { + t.Fatalf("targets were not cleared: %#v", a.Targets) + } + if len(a.Certificates) != 0 { + t.Fatalf("certificates were not cleared: %#v", a.Certificates) + } + }, + }, + "an account owner can delete a single certificate identified by sha256 hash of the content": { Requests: []Request{ {