Skip to content

Commit

Permalink
fix revoke-certificate, platform cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-yuhh committed Aug 10, 2023
1 parent c40282c commit 573dddc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
44 changes: 44 additions & 0 deletions x/cert/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package keeper_test

import (
"github.com/stretchr/testify/require"
"testing"
"time"

tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

sdk "github.com/cosmos/cosmos-sdk/types"

shentuapp "github.com/shentufoundation/shentu/v2/app"
"github.com/shentufoundation/shentu/v2/x/cert/keeper"
"github.com/shentufoundation/shentu/v2/x/cert/types"
)

func TestMsgServer_Certificate(t *testing.T) {
ctx, certKeeper, msgServer, addrs := DoInit(t)

content := types.AssembleContent("identity", addrs[1].String())
_, err := msgServer.IssueCertificate(sdk.WrapSDKContext(ctx), types.NewMsgIssueCertificate(content, "", "", "", addrs[0]))
require.NoError(t, err)

certificateID := uint64(1)
_, err = msgServer.RevokeCertificate(sdk.WrapSDKContext(ctx), types.NewMsgRevokeCertificate(addrs[0], certificateID, ""))
require.NoError(t, err)

_, err = certKeeper.GetCertificateByID(ctx, certificateID)
require.Error(t, err)
}

func DoInit(t *testing.T) (sdk.Context, keeper.Keeper, types.MsgServer, []sdk.AccAddress) {
app := shentuapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{Time: time.Now().UTC()})
addrs := shentuapp.AddTestAddrs(app, ctx, 5, sdk.NewInt(80000*1e6))
ok := app.CertKeeper
msgServer := keeper.NewMsgServerImpl(ok)
ctx = ctx.WithValue("msgServer", msgServer).WithValue("t", t).WithValue("ok", ok)

ok.SetCertifier(ctx, types.Certifier{
Address: addrs[0].String(),
})
return ctx, ok, msgServer, addrs
}
1 change: 0 additions & 1 deletion x/cert/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func Test_GetNewCertificateID(t *testing.T) {
c2, err := types.NewCertificate("compilation", "sourcodehash0", "compiler1",
"bytecodehash1", "", addrs[0])
require.NoError(t, err)
require.NotEqual(t, c2.ToString(), "")

id2 := app.CertKeeper.GetNextCertificateID(ctx)
c2.CertificateId = id2
Expand Down

0 comments on commit 573dddc

Please sign in to comment.