Skip to content

Commit

Permalink
Clear account targets on transfer (#1193)
Browse files Browse the repository at this point in the history
* account targets and certificates are cleared on transfer, added unit testing

* updated CHANGELOG.md to reflect changes
  • Loading branch information
fdymylja authored Apr 2, 2020
1 parent 6a4c371 commit b9b8862
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions cmd/bnsd/x/account/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
99 changes: 99 additions & 0 deletions cmd/bnsd/x/account/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
{
Expand Down

0 comments on commit b9b8862

Please sign in to comment.