Skip to content

Commit

Permalink
🔀 Merge #92 ✨ Add authorizations for iscn and likenft
Browse files Browse the repository at this point in the history
  • Loading branch information
williamchong authored Jan 19, 2023
2 parents d0e6f86 + 8b869bc commit 011d519
Show file tree
Hide file tree
Showing 31 changed files with 5,688 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ codegen:
go generate ./...

test: codegen
go test -v ./...
go test -timeout 20m -v ./...

clean:
rm -rf $(BUILDDIR)/ artifacts/
Expand Down
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ require (
github.com/ipfs/go-cid v0.0.7
github.com/multiformats/go-multihash v0.0.15
github.com/rakyll/statik v0.1.7
github.com/regen-network/cosmos-proto v0.3.1
github.com/spf13/cast v1.5.0
github.com/spf13/cobra v1.6.0
github.com/stretchr/testify v1.8.0
github.com/tendermint/tendermint v0.34.23
github.com/tendermint/tm-db v0.6.6
google.golang.org/genproto v0.0.0-20221014213838-99cd37c6964a
google.golang.org/grpc v1.50.1
google.golang.org/genproto v0.0.0-20221207170731-23e4bf6bdc37
google.golang.org/grpc v1.51.0
google.golang.org/protobuf v1.28.2-0.20220831092852-f930b1dc76e8
)

Expand Down Expand Up @@ -105,7 +106,6 @@ require (
github.com/prometheus/common v0.34.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/regen-network/cosmos-proto v0.3.1 // indirect
github.com/rs/cors v1.8.2 // indirect
github.com/rs/zerolog v1.27.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
Expand All @@ -123,10 +123,10 @@ require (
go.etcd.io/bbolt v1.3.6 // indirect
golang.org/x/crypto v0.1.0 // indirect
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
golang.org/x/net v0.1.0 // indirect
golang.org/x/sys v0.1.0 // indirect
golang.org/x/term v0.1.0 // indirect
golang.org/x/text v0.4.0 // indirect
golang.org/x/net v0.3.0 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/term v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -936,8 +936,8 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0=
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/net v0.3.0 h1:VWL6FNY2bEEmsGVKabSlHu5Irp34xmMRoqb/9lF9lxk=
golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -1033,13 +1033,13 @@ golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0 h1:g6Z6vPFA9dYBAF7DWcH6sCcOntplXsDKcliusYijMlw=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.3.0 h1:qoo4akIqOcDME5bhc/NgxUdovd6BSS2uMsVjB56q1xI=
golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand All @@ -1049,8 +1049,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM=
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down Expand Up @@ -1185,8 +1185,8 @@ google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6D
google.golang.org/genproto v0.0.0-20210108203827-ffc7fda8c3d7/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20210126160654-44e461bb6506/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20210226172003-ab064af71705/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20221014213838-99cd37c6964a h1:GH6UPn3ixhWcKDhpnEC55S75cerLPdpp3hrhfKYjZgw=
google.golang.org/genproto v0.0.0-20221014213838-99cd37c6964a/go.mod h1:1vXfmgAz9N9Jx0QA82PqRVauvCz1SGSz739p0f183jM=
google.golang.org/genproto v0.0.0-20221207170731-23e4bf6bdc37 h1:jmIfw8+gSvXcZSgaFAGyInDXeWzUhvYH57G/5GKMn70=
google.golang.org/genproto v0.0.0-20221207170731-23e4bf6bdc37/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM=
google.golang.org/grpc v1.33.2 h1:EQyQC3sa8M+p6Ulc8yy9SWSS2GVwyRc83gAbG8lrl4o=
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
Expand Down
6 changes: 3 additions & 3 deletions proto/buf.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ deps:
- remote: buf.build
owner: cosmos
repository: cosmos-sdk
commit: 5a0f723faed2400d8f1ed75519f1b063
commit: 45fa84fad36545ad9ad0562e81916c08
- remote: buf.build
owner: cosmos
repository: gogo-proto
commit: bee5511075b7499da6178d9e4aaa628b
commit: 34d970b699f84aa382f3c29773a60836
- remote: buf.build
owner: googleapis
repository: googleapis
commit: 40f07f5b563941f2b20b991a7aedd53d
commit: 783e4b5374fa488ab068d08af9658438
14 changes: 14 additions & 0 deletions proto/likechain/iscn/authz.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
syntax = "proto3";

package likechain.iscn;

import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";

option go_package = "github.com/likecoin/likecoin-chain/v3/x/iscn/types";

message UpdateAuthorization {
option (cosmos_proto.implements_interface) = "Authorization";

string iscn_id_prefix = 1;
}
92 changes: 92 additions & 0 deletions proto/likechain/likenft/v1/authz.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
syntax = "proto3";

package likechain.likenft.v1;

import "cosmos_proto/cosmos.proto";

option go_package = "github.com/likecoin/likecoin-chain/v3/x/likenft/types";

message CreateRoyaltyConfigAuthorization {
option (cosmos_proto.implements_interface) = "Authorization";

string class_id = 1;
}

message UpdateRoyaltyConfigAuthorization {
option (cosmos_proto.implements_interface) = "Authorization";

string class_id = 1;
}

message DeleteRoyaltyConfigAuthorization {
option (cosmos_proto.implements_interface) = "Authorization";

string class_id = 1;
}

message CreateListingAuthorization {
option (cosmos_proto.implements_interface) = "Authorization";

string class_id = 1;
string nft_id = 2;
}

message UpdateListingAuthorization {
option (cosmos_proto.implements_interface) = "Authorization";

string class_id = 1;
string nft_id = 2;
}

message DeleteListingAuthorization {
option (cosmos_proto.implements_interface) = "Authorization";

string class_id = 1;
string nft_id = 2;
}

message CreateOfferAuthorization {
option (cosmos_proto.implements_interface) = "Authorization";

string class_id = 1;
string nft_id = 2;
}

message UpdateOfferAuthorization {
option (cosmos_proto.implements_interface) = "Authorization";

string class_id = 1;
string nft_id = 2;
}

message DeleteOfferAuthorization {
option (cosmos_proto.implements_interface) = "Authorization";

string class_id = 1;
string nft_id = 2;
}

message NewClassAuthorization {
option (cosmos_proto.implements_interface) = "Authorization";

string iscn_id_prefix = 1;
}

message UpdateClassAuthorization {
option (cosmos_proto.implements_interface) = "Authorization";

string class_id = 1;
}

message MintNFTAuthorization {
option (cosmos_proto.implements_interface) = "Authorization";

string class_id = 1;
}

message SendNFTAuthorization {
option (cosmos_proto.implements_interface) = "Authorization";

string class_id = 1;
string id = 2;
}
23 changes: 23 additions & 0 deletions testutil/testing_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ func (app *TestingApp) DeliverMsgNoError(t *testing.T, msg sdk.Msg, priv cryptot
return app.DeliverMsgsNoError(t, []sdk.Msg{msg}, priv)
}

func (app *TestingApp) DeliverMsgSimError(t *testing.T, msg sdk.Msg, priv cryptotypes.PrivKey, errContains string, args ...interface{}) {
_, err, simErr, _ := app.DeliverMsg(msg, priv)
require.NoError(t, err)
require.ErrorContains(t, simErr, errContains, args...)
}

func GetEventAttribute(events sdk.Events, typ string, attrKey []byte) []byte {
for _, e := range events {
if e.Type == typ {
Expand All @@ -231,3 +237,20 @@ func GetEventAttribute(events sdk.Events, typ string, attrKey []byte) []byte {
}
return nil
}

func GetIscnIdFromResult(t *testing.T, result *sdk.Result) types.IscnId {
events := result.GetEvents()
iscnIdStrBytes := GetEventAttribute(events, "iscn_record", []byte("iscn_id"))
require.NotNil(t, iscnIdStrBytes)
iscnId, err := types.ParseIscnId(string(iscnIdStrBytes))
require.NoError(t, err)
return iscnId
}

func GetClassIdFromResult(t *testing.T, result *sdk.Result) string {
events := result.GetEvents()
classIdEvent := GetEventAttribute(events, "likechain.likenft.v1.EventNewClass", []byte("class_id"))
require.NotNil(t, classIdEvent)
// strip the leading and trailing quotes
return string(classIdEvent[1 : len(classIdEvent)-1])
}
80 changes: 80 additions & 0 deletions x/iscn/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import (
"fmt"
"math/rand"
"testing"
"time"

"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/authz"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"

"github.com/likecoin/likecoin-chain/v3/x/iscn/keeper"
Expand Down Expand Up @@ -847,3 +849,81 @@ func TestSimulation(t *testing.T) {
testWithRand(r)
}
}

func TestUpdateAuthorization(t *testing.T) {
var msg sdk.Msg
app := testutil.SetupTestApp([]testutil.GenesisBalance{
{addr1.String(), "1000000000000000000nanolike"},
{addr2.String(), "1000000000000000000nanolike"},
{addr3.String(), "1000000000000000000nanolike"},
})

app.NextHeader(1234567890)
app.SetForTx()
record := types.IscnRecord{
RecordNotes: "some update",
ContentFingerprints: []string{fingerprint1},
Stakeholders: []types.IscnInput{stakeholder1, stakeholder2},
ContentMetadata: contentMetadata1,
}
msg = types.NewMsgCreateIscnRecord(addr1, &record)
result := app.DeliverMsgNoError(t, msg, priv1)
iscnId := testutil.GetIscnIdFromResult(t, result)

record = types.IscnRecord{
RecordNotes: "new update",
ContentFingerprints: []string{fingerprint1, fingerprint2},
Stakeholders: []types.IscnInput{stakeholder1, stakeholder2},
ContentMetadata: contentMetadata2,
}
msg, err := authz.NewMsgGrant(addr1, addr2, types.NewUpdateAuthorization(iscnId.Prefix.String()), time.Unix(2000000000, 0))
require.NoError(t, err)
app.DeliverMsgNoError(t, msg, priv1)

updateMsg := types.NewMsgUpdateIscnRecord(addr1, iscnId, &record)
msgExec := authz.NewMsgExec(addr2, []sdk.Msg{updateMsg})
msg = &msgExec
result = app.DeliverMsgNoError(t, msg, priv2)

events := result.GetEvents()
iscnId2StrBytes := testutil.GetEventAttribute(events, "iscn_record", []byte("iscn_id"))
require.NotNil(t, iscnId2StrBytes)
iscnId2, err := types.ParseIscnId(string(iscnId2StrBytes))
require.NoError(t, err)
require.Equal(t, iscnId.Prefix, iscnId2.Prefix)
require.Equal(t, iscnId.Version+1, iscnId2.Version)
ipld2StrBytes := testutil.GetEventAttribute(events, "iscn_record", []byte("ipld"))
require.NotNil(t, ipld2StrBytes)
owner2StrBytes := testutil.GetEventAttribute(events, "iscn_record", []byte("owner"))
require.NotNil(t, owner2StrBytes)
require.Equal(t, string(owner2StrBytes), addr1.String())

updateMsg = types.NewMsgUpdateIscnRecord(addr1, iscnId2, &record)
msgExec = authz.NewMsgExec(addr3, []sdk.Msg{updateMsg})
msg = &msgExec
_, _, simErr, _ := app.DeliverMsg(msg, priv3)
require.ErrorContains(t, simErr, "authorization not found")

record = types.IscnRecord{
RecordNotes: "another record",
ContentFingerprints: []string{fingerprint1, fingerprint2},
Stakeholders: []types.IscnInput{stakeholder1, stakeholder2},
ContentMetadata: contentMetadata2,
}
msg = types.NewMsgCreateIscnRecord(addr1, &record)
result = app.DeliverMsgNoError(t, msg, priv1)
iscnId3 := testutil.GetIscnIdFromResult(t, result)

record = types.IscnRecord{
RecordNotes: "another record updated",
ContentFingerprints: []string{fingerprint1, fingerprint2},
Stakeholders: []types.IscnInput{stakeholder1, stakeholder2},
ContentMetadata: contentMetadata2,
}

updateMsg = types.NewMsgUpdateIscnRecord(addr1, iscnId3, &record)
msgExec = authz.NewMsgExec(addr2, []sdk.Msg{updateMsg})
msg = &msgExec
_, _, simErr, _ = app.DeliverMsg(msg, priv2)
require.ErrorContains(t, simErr, "ISCN ID prefix mismatch")
}
Loading

0 comments on commit 011d519

Please sign in to comment.