diff --git a/go.mod b/go.mod index 62286d6..2351c58 100644 --- a/go.mod +++ b/go.mod @@ -7,8 +7,8 @@ require ( github.com/filecoin-project/go-address v1.1.0 github.com/filecoin-project/go-jsonrpc v0.1.5 github.com/filecoin-project/go-state-types v0.11.1 - github.com/filecoin-project/venus v1.11.0 - github.com/filecoin-project/venus-auth v1.11.0 + github.com/filecoin-project/venus v1.11.2-0.20230511060025-c6ed196f613c + github.com/filecoin-project/venus-auth v1.11.1-0.20230511013901-7829b3effbcd github.com/google/uuid v1.3.0 github.com/gorilla/mux v1.8.0 github.com/ipfs-force-community/metrics v1.0.1-0.20220719063006-2c54bb379466 diff --git a/go.sum b/go.sum index abe3261..b666ced 100644 --- a/go.sum +++ b/go.sum @@ -408,11 +408,11 @@ github.com/filecoin-project/specs-storage v0.2.2/go.mod h1:6cc/lncmAxMUocPi0z1EP github.com/filecoin-project/storetheindex v0.3.5/go.mod h1:0r3d0kSpK63O6AvLr1CjAINLi+nWD49clzcnKV+GLpI= github.com/filecoin-project/test-vectors/schema v0.0.5/go.mod h1:iQ9QXLpYWL3m7warwvK1JC/pTri8mnfEmKygNDqqY6E= github.com/filecoin-project/venus v1.2.4/go.mod h1:hJULXHGAnWuq5S5KRtPkwbT8DqgM9II7NwyNU7t59D0= -github.com/filecoin-project/venus v1.11.0 h1:cH7ydd+O2dw7zg8tKfeiuwVd5SokZ8TBu+WoBU60pAA= -github.com/filecoin-project/venus v1.11.0/go.mod h1:H8A3djsrHKRWuKnJI/8Y6xZRudbV9V2x5NIP8/PVPfQ= +github.com/filecoin-project/venus v1.11.2-0.20230511060025-c6ed196f613c h1:f8ZwGwjnGTa4mlH8x7yqKTdw+AIcHMUd6hO2AtwRokQ= +github.com/filecoin-project/venus v1.11.2-0.20230511060025-c6ed196f613c/go.mod h1:DA73O3dB54B9dxxxQncq0ZGy5f+zwY+hRMgnaiHdhrk= github.com/filecoin-project/venus-auth v1.3.2/go.mod h1:m5Jog2GYxztwP7w3m/iJdv/V1/bTcAVU9rm/CbhxRQU= -github.com/filecoin-project/venus-auth v1.11.0 h1:9PBswWxc113vqaHABMcRyMm+1BtlJCwOFTPQJg/OVtQ= -github.com/filecoin-project/venus-auth v1.11.0/go.mod h1:aBfIfNxQkdcY8Rk5wrQn9qRtJpH4RTDdc10Ac+ferzs= +github.com/filecoin-project/venus-auth v1.11.1-0.20230511013901-7829b3effbcd h1:l02UJuEbSUIBi3NC/+17K2gBbAzsUNQg42rNCXskOBc= +github.com/filecoin-project/venus-auth v1.11.1-0.20230511013901-7829b3effbcd/go.mod h1:PoTmfEn5lljjAQThBzX0+friJYGgi7Z3VLLujkOkCT4= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/flynn/noise v0.0.0-20180327030543-2492fe189ae6/go.mod h1:1i71OnUq3iUe1ma7Lr6yG6/rjvM3emb6yoL7xLFzcVQ= github.com/flynn/noise v1.0.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag= @@ -2779,7 +2779,6 @@ gorm.io/driver/mysql v1.1.1/go.mod h1:KdrTanmfLPPyAOeYGyG+UpDys7/7eeWT1zCq+oekYn gorm.io/gorm v1.21.9/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0= gorm.io/gorm v1.21.12 h1:3fQM0Eiz7jcJEhPggHEpoYnsGZqynMzverL77DV40RM= gorm.io/gorm v1.21.12/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0= -gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJdjuHRquDANNeA4x7B8WQ9o= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/integrate_test/mock_deamon.go b/integrate_test/mock_deamon.go index 8dc8210..71bb40e 100644 --- a/integrate_test/mock_deamon.go +++ b/integrate_test/mock_deamon.go @@ -19,6 +19,7 @@ import ( "github.com/ipfs-force-community/venus-gateway/config" "github.com/filecoin-project/venus-auth/auth" + "github.com/filecoin-project/venus-auth/core" "github.com/filecoin-project/venus-auth/jwtclient" v2API "github.com/filecoin-project/venus/venus-shared/api/gateway/v2" @@ -90,7 +91,7 @@ func MockMain(ctx context.Context, validateMiner []address.Address, repoPath str if len(cfg.RateLimit.Redis) > 0 { limiter, err := ratelimit.NewRateLimitHandler(cfg.RateLimit.Redis, nil, - &jwtclient.ValueFromCtx{}, + &core.ValueFromCtx{}, authClient, logging.Logger("rate-limit")) _ = logging.SetLogLevel("rate-limit", "info") diff --git a/main.go b/main.go index 197d908..33ea921 100644 --- a/main.go +++ b/main.go @@ -26,6 +26,7 @@ import ( "github.com/filecoin-project/go-jsonrpc" + "github.com/filecoin-project/venus-auth/core" "github.com/filecoin-project/venus-auth/jwtclient" _ "github.com/filecoin-project/venus/pkg/crypto/bls" @@ -195,7 +196,7 @@ func RunMain(ctx context.Context, repoPath string, cfg *config.Config) error { if len(cfg.RateLimit.Redis) > 0 { limiter, err := ratelimit.NewRateLimitHandler(cfg.RateLimit.Redis, nil, - &jwtclient.ValueFromCtx{}, + &core.ValueFromCtx{}, jwtclient.WarpLimitFinder(remoteJwtCli), logging.Logger("rate-limit")) _ = logging.SetLogLevel("rate-limit", "info") diff --git a/marketevent/market_event.go b/marketevent/market_event.go index 85b2410..847c4f7 100644 --- a/marketevent/market_event.go +++ b/marketevent/market_event.go @@ -15,8 +15,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - - "github.com/filecoin-project/venus-auth/jwtclient" + "github.com/filecoin-project/venus-auth/core" v2API "github.com/filecoin-project/venus/venus-shared/api/gateway/v2" sharedTypes "github.com/filecoin-project/venus/venus-shared/types" @@ -51,7 +50,7 @@ func NewMarketEventStream(ctx context.Context, validator validator.IAuthMinerVal } func (m *MarketEventStream) ListenMarketEvent(ctx context.Context, policy *types2.MarketRegisterPolicy) (<-chan *types2.RequestEvent, error) { - ip, exist := jwtclient.CtxGetTokenLocation(ctx) + ip, exist := core.CtxGetTokenLocation(ctx) if !exist { return nil, fmt.Errorf("ip not exist") } diff --git a/marketevent/market_event_test.go b/marketevent/market_event_test.go index 322ed93..0f95261 100644 --- a/marketevent/market_event_test.go +++ b/marketevent/market_event_test.go @@ -12,7 +12,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/venus-auth/auth" - "github.com/filecoin-project/venus-auth/jwtclient" + "github.com/filecoin-project/venus-auth/core" sharedTypes "github.com/filecoin-project/venus/venus-shared/types" @@ -34,7 +34,7 @@ func TestListenMarketEvent(t *testing.T) { marketEvent := setupMarketEvent(t, supportAccount, minerAddr) client := NewMarketEventClient(marketEvent, minerAddr, nil, log.With()) - go client.ListenMarketRequest(jwtclient.CtxWithName(jwtclient.CtxWithTokenLocation(ctx, "127.1.1.1"), supportAccount)) + go client.ListenMarketRequest(core.CtxWithName(core.CtxWithTokenLocation(ctx, "127.1.1.1"), supportAccount)) client.WaitReady(ctx) }) @@ -47,7 +47,7 @@ func TestListenMarketEvent(t *testing.T) { marketEvent := setupMarketEvent(t, supportAccount, minerAddr) client := NewMarketEventClient(marketEvent, addrGetter(), nil, log.With()) // stm: @VENUSGATEWAY_MARKET_EVENT_LISTEN_MARKET_EVENT_002 - err := client.listenMarketRequestOnce(jwtclient.CtxWithName(jwtclient.CtxWithTokenLocation(ctx, "127.1.1.1"), supportAccount)) + err := client.listenMarketRequestOnce(core.CtxWithName(core.CtxWithTokenLocation(ctx, "127.1.1.1"), supportAccount)) require.Contains(t, err.Error(), "not exist") }) @@ -60,7 +60,7 @@ func TestListenMarketEvent(t *testing.T) { marketEvent := setupMarketEvent(t, supportAccount, minerAddr) client := NewMarketEventClient(marketEvent, minerAddr, nil, log.With()) // stm: @VENUSGATEWAY_MARKET_EVENT_LISTEN_MARKET_EVENT_003 - err := client.listenMarketRequestOnce(jwtclient.CtxWithName(ctx, supportAccount)) + err := client.listenMarketRequestOnce(core.CtxWithName(ctx, supportAccount)) require.Contains(t, err.Error(), "ip not exist") }) } @@ -76,7 +76,7 @@ func TestUnsealed(t *testing.T) { marketEvent := setupMarketEvent(t, walletAccount, minerAddr) handler := testhelper.NewMarketHandler(t) client := NewMarketEventClient(marketEvent, minerAddr, handler, log.With()) - go client.ListenMarketRequest(jwtclient.CtxWithName(jwtclient.CtxWithTokenLocation(ctx, "127.1.1.1"), walletAccount)) + go client.ListenMarketRequest(core.CtxWithName(core.CtxWithTokenLocation(ctx, "127.1.1.1"), walletAccount)) client.WaitReady(ctx) sid := abi.SectorNumber(10) @@ -97,7 +97,7 @@ func TestUnsealed(t *testing.T) { marketEvent := setupMarketEvent(t, walletAccount, minerAddr) handler := testhelper.NewMarketHandler(t) client := NewMarketEventClient(marketEvent, minerAddr, handler, log.With()) - go client.ListenMarketRequest(jwtclient.CtxWithName(jwtclient.CtxWithTokenLocation(ctx, "127.1.1.1"), walletAccount)) + go client.ListenMarketRequest(core.CtxWithName(core.CtxWithTokenLocation(ctx, "127.1.1.1"), walletAccount)) client.WaitReady(ctx) sid := abi.SectorNumber(10) @@ -118,7 +118,7 @@ func TestUnsealed(t *testing.T) { marketEvent := setupMarketEvent(t, walletAccount, minerAddr) handler := testhelper.NewMarketHandler(t) client := NewMarketEventClient(marketEvent, minerAddr, handler, log.With()) - go client.ListenMarketRequest(jwtclient.CtxWithName(jwtclient.CtxWithTokenLocation(ctx, "127.1.1.1"), walletAccount)) + go client.ListenMarketRequest(core.CtxWithName(core.CtxWithTokenLocation(ctx, "127.1.1.1"), walletAccount)) client.WaitReady(ctx) sid := abi.SectorNumber(10) @@ -143,7 +143,7 @@ func TestListMarketConnectionsState(t *testing.T) { marketEvent := setupMarketEvent(t, walletAccount, minerAddr) handler := testhelper.NewMarketHandler(t) client := NewMarketEventClient(marketEvent, minerAddr, handler, log.With()) - go client.ListenMarketRequest(jwtclient.CtxWithName(jwtclient.CtxWithTokenLocation(ctx, "127.1.1.1"), walletAccount)) + go client.ListenMarketRequest(core.CtxWithName(core.CtxWithTokenLocation(ctx, "127.1.1.1"), walletAccount)) client.WaitReady(ctx) // stm: @VENUSGATEWAY_MARKET_EVENT_LIST_MARKET_CONNECTIONS_STATE_001 diff --git a/proofevent/proof_event.go b/proofevent/proof_event.go index a8d1a5d..2debcee 100644 --- a/proofevent/proof_event.go +++ b/proofevent/proof_event.go @@ -14,13 +14,12 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/venus-auth/core" "github.com/ipfs-force-community/venus-gateway/metrics" "github.com/ipfs-force-community/venus-gateway/types" "github.com/ipfs-force-community/venus-gateway/validator" - "github.com/filecoin-project/venus-auth/jwtclient" - "github.com/filecoin-project/venus/venus-shared/actors/builtin" v2API "github.com/filecoin-project/venus/venus-shared/api/gateway/v2" sharedTypes "github.com/filecoin-project/venus/venus-shared/types" @@ -51,7 +50,7 @@ func NewProofEventStream(ctx context.Context, validator validator.IAuthMinerVali } func (e *ProofEventStream) ListenProofEvent(ctx context.Context, policy *sharedGatewayTypes.ProofRegisterPolicy) (<-chan *sharedGatewayTypes.RequestEvent, error) { - ip, exist := jwtclient.CtxGetTokenLocation(ctx) + ip, exist := core.CtxGetTokenLocation(ctx) if !exist { return nil, fmt.Errorf("ip not exist") } diff --git a/proofevent/proof_event_test.go b/proofevent/proof_event_test.go index 2d886cc..8438762 100644 --- a/proofevent/proof_event_test.go +++ b/proofevent/proof_event_test.go @@ -15,7 +15,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/network" - "github.com/filecoin-project/venus-auth/jwtclient" + "github.com/filecoin-project/venus-auth/core" "github.com/filecoin-project/venus/venus-shared/actors/builtin" types2 "github.com/filecoin-project/venus/venus-shared/types" types "github.com/filecoin-project/venus/venus-shared/types/gateway" @@ -33,7 +33,7 @@ func TestListenProofEvent(t *testing.T) { t.Run("init connect", func(t *testing.T) { proof := setupProofEvent(t, []address.Address{addr1}) ctx, cancel := context.WithCancel(context.Background()) - ctx = jwtclient.CtxWithTokenLocation(ctx, "127.1.1.1") + ctx = core.CtxWithTokenLocation(ctx, "127.1.1.1") // stm: @VENUSGATEWAY_PROOF_EVENT_LISTEN_PROOF_EVENT_001 requestCh, err := proof.ListenProofEvent(ctx, &types.ProofRegisterPolicy{ MinerAddress: addr1, @@ -67,7 +67,7 @@ func TestListenProofEvent(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) proofClient := NewProofEvent(proof, addr1, testhelper.NewTimeoutProofHandler(time.Second), log.With()) // stm: - go proofClient.ListenProofRequest(jwtclient.CtxWithTokenLocation(ctx, "127.1.1.1")) + go proofClient.ListenProofRequest(core.CtxWithTokenLocation(ctx, "127.1.1.1")) proofClient.WaitReady(ctx) // fill request @@ -100,7 +100,7 @@ func TestListenProofEvent(t *testing.T) { proof := setupProofEvent(t, []address.Address{addr1}) ctx, cancel := context.WithCancel(context.Background()) defer cancel() - ctx = jwtclient.CtxWithTokenLocation(ctx, "127.1.1.1") + ctx = core.CtxWithTokenLocation(ctx, "127.1.1.1") // stm: @VENUSGATEWAY_PROOF_EVENT_LISTEN_PROOF_EVENT_003 _, err := proof.ListenProofEvent(ctx, &types.ProofRegisterPolicy{ @@ -148,7 +148,7 @@ func TestComputeProofEvent(t *testing.T) { handler := testhelper.NewProofHander(t, expectInfo, expectRand, expectEpoch, expectVersion, expectProof, false) proofClient := NewProofEvent(proof, addr, handler, log.With()) - go proofClient.ListenProofRequest(jwtclient.CtxWithTokenLocation(ctx, "127.1.1.1")) + go proofClient.ListenProofRequest(core.CtxWithTokenLocation(ctx, "127.1.1.1")) proofClient.WaitReady(ctx) // stm: @VENUSGATEWAY_PROOF_EVENT_COMPUTE_PROOF_001 @@ -181,7 +181,7 @@ func TestComputeProofEvent(t *testing.T) { handler := testhelper.NewProofHander(t, expectInfo, expectRand, expectEpoch, expectVersion, expectProof, false) proofClient := NewProofEvent(proof, addr, handler, log.With()) - ctx = jwtclient.CtxWithTokenLocation(ctx, "127.1.1.1") + ctx = core.CtxWithTokenLocation(ctx, "127.1.1.1") go proofClient.ListenProofRequest(ctx) proofClient.WaitReady(ctx) @@ -214,7 +214,7 @@ func TestComputeProofEvent(t *testing.T) { handler := testhelper.NewProofHander(t, expectInfo, expectRand, expectEpoch, expectVersion, nil, true) proofClient := NewProofEvent(proof, addr, handler, log.With()) - go proofClient.ListenProofRequest(jwtclient.CtxWithTokenLocation(ctx, "127.1.1.1")) + go proofClient.ListenProofRequest(core.CtxWithTokenLocation(ctx, "127.1.1.1")) proofClient.WaitReady(ctx) // stm: @VENUSGATEWAY_PROOF_EVENT_COMPUTE_PROOF_004 @@ -232,7 +232,7 @@ func TestComputeProofEvent(t *testing.T) { t.Run("incorrect result error", func(t *testing.T) { proof := setupProofEvent(t, []address.Address{addr}) { - ctx := jwtclient.CtxWithTokenLocation(context.Background(), "127.1.1.1") + ctx := core.CtxWithTokenLocation(context.Background(), "127.1.1.1") requestCh, err := proof.ListenProofEvent(ctx, &types.ProofRegisterPolicy{ MinerAddress: addr, }) @@ -264,7 +264,7 @@ func TestComputeProofEvent(t *testing.T) { t.Run("mistake request id error", func(t *testing.T) { proof := setupProofEvent(t, []address.Address{addr}) - ctx := jwtclient.CtxWithTokenLocation(context.Background(), "127.1.1.1") + ctx := core.CtxWithTokenLocation(context.Background(), "127.1.1.1") _, err := proof.ListenProofEvent(ctx, &types.ProofRegisterPolicy{ MinerAddress: addr, }) @@ -289,14 +289,14 @@ func TestListConnectedMiners(t *testing.T) { defer cancel() { proofClient := NewProofEvent(proof, addr1, nil, log.With()) - ctx = jwtclient.CtxWithTokenLocation(ctx, "127.1.1.1") + ctx = core.CtxWithTokenLocation(ctx, "127.1.1.1") go proofClient.ListenProofRequest(ctx) proofClient.WaitReady(ctx) } { proofClient := NewProofEvent(proof, addr2, nil, log.With()) - ctx = jwtclient.CtxWithTokenLocation(ctx, "127.1.1.1") + ctx = core.CtxWithTokenLocation(ctx, "127.1.1.1") go proofClient.ListenProofRequest(ctx) proofClient.WaitReady(ctx) } @@ -314,14 +314,14 @@ func TestListMinerConnection(t *testing.T) { { proofClient := NewProofEvent(proof, addr1, nil, log.With()) - ctx = jwtclient.CtxWithTokenLocation(ctx, "127.1.1.1") + ctx = core.CtxWithTokenLocation(ctx, "127.1.1.1") go proofClient.ListenProofRequest(ctx) proofClient.WaitReady(ctx) } { proofClient := NewProofEvent(proof, addr1, nil, log.With()) - ctx = jwtclient.CtxWithTokenLocation(ctx, "127.1.1.2") + ctx = core.CtxWithTokenLocation(ctx, "127.1.1.2") go proofClient.ListenProofRequest(ctx) proofClient.WaitReady(ctx) } diff --git a/validator/miner_validator.go b/validator/miner_validator.go index 6a9811e..66647dd 100644 --- a/validator/miner_validator.go +++ b/validator/miner_validator.go @@ -21,7 +21,7 @@ type IAuthMinerValidator interface { var _ IAuthMinerValidator = (*AuthMinerValidator)(nil) func (amv *AuthMinerValidator) Validate(ctx context.Context, miner address.Address) error { - account, exist := jwtclient.CtxGetName(ctx) + account, exist := core.CtxGetName(ctx) if !exist { return fmt.Errorf("user name not exist in rpc context") } diff --git a/validator/miner_validator_test.go b/validator/miner_validator_test.go index cb344f8..f71581e 100644 --- a/validator/miner_validator_test.go +++ b/validator/miner_validator_test.go @@ -12,7 +12,7 @@ import ( "github.com/filecoin-project/venus/venus-shared/types" "github.com/filecoin-project/venus-auth/auth" - "github.com/filecoin-project/venus-auth/jwtclient" + "github.com/filecoin-project/venus-auth/core" "github.com/ipfs-force-community/venus-gateway/validator/mocks" ) @@ -72,7 +72,7 @@ func TestAuthMinerValidator_Validate(t *testing.T) { authClient.AddMockUser(ctx, arg.user) var ctx = context.Background() if userName != "" { - ctx = jwtclient.CtxWithName(ctx, userName) + ctx = core.CtxWithName(ctx, userName) } // miner not exists diff --git a/walletevent/wallet_event.go b/walletevent/wallet_event.go index 2385c13..9ba04d5 100644 --- a/walletevent/wallet_event.go +++ b/walletevent/wallet_event.go @@ -20,6 +20,7 @@ import ( "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/venus-auth/auth" + "github.com/filecoin-project/venus-auth/core" "github.com/filecoin-project/venus-auth/jwtclient" wcrypto "github.com/filecoin-project/venus/pkg/crypto" @@ -60,12 +61,12 @@ func NewWalletEventStream(ctx context.Context, authClient jwtclient.IAuthClient, } func (w *WalletEventStream) ListenWalletEvent(ctx context.Context, policy *sharedGatewayTypes.WalletRegisterPolicy) (<-chan *sharedGatewayTypes.RequestEvent, error) { - walletAccount, exit := jwtclient.CtxGetName(ctx) + walletAccount, exit := core.CtxGetName(ctx) if !exit { return nil, errors.New("unable to get account name in method ListenWalletEvent request") } - ip, _ := jwtclient.CtxGetTokenLocation(ctx) // todo sure exit? + ip, _ := core.CtxGetTokenLocation(ctx) // todo sure exit? out := make(chan *sharedGatewayTypes.RequestEvent, w.cfg.RequestQueueSize) walletLog := log.With("account", walletAccount).With("ip", ip) ctx, _ = tag.New(ctx, tag.Upsert(metrics.WalletAccountKey, walletAccount), tag.Upsert(metrics.IPKey, ip)) @@ -155,7 +156,7 @@ func (w *WalletEventStream) ResponseWalletEvent(ctx context.Context, resp *share } func (w *WalletEventStream) SupportNewAccount(ctx context.Context, channelId sharedTypes.UUID, account string) error { - walletAccount, exit := jwtclient.CtxGetName(ctx) + walletAccount, exit := core.CtxGetName(ctx) if !exit { return errors.New("unable to get account name in method SupportNewAccount request") } @@ -171,7 +172,7 @@ func (w *WalletEventStream) SupportNewAccount(ctx context.Context, channelId sha } func (w *WalletEventStream) AddNewAddress(ctx context.Context, channelId sharedTypes.UUID, addrs []address.Address) error { - walletAccount, exit := jwtclient.CtxGetName(ctx) + walletAccount, exit := core.CtxGetName(ctx) if !exit { return errors.New("unable to get account name in method AddNewAddress request") } @@ -214,7 +215,7 @@ func (w *WalletEventStream) AddNewAddress(ctx context.Context, channelId sharedT } func (w *WalletEventStream) RemoveAddress(ctx context.Context, channelId sharedTypes.UUID, addrs []address.Address) error { - walletAccount, exit := jwtclient.CtxGetName(ctx) + walletAccount, exit := core.CtxGetName(ctx) if !exit { return errors.New("unable to get account name in method RemoveAddress request") } diff --git a/walletevent/wallet_event_test.go b/walletevent/wallet_event_test.go index 23c443d..ab01cd4 100644 --- a/walletevent/wallet_event_test.go +++ b/walletevent/wallet_event_test.go @@ -14,7 +14,7 @@ import ( logging "github.com/ipfs/go-log/v2" "github.com/filecoin-project/venus-auth/auth" - "github.com/filecoin-project/venus-auth/jwtclient" + "github.com/filecoin-project/venus-auth/core" _ "github.com/filecoin-project/venus/pkg/crypto/secp" sharedTypes "github.com/filecoin-project/venus/venus-shared/types" @@ -33,7 +33,7 @@ func TestListenWalletEvent(t *testing.T) { walletEvent := setupWalletEvent(t, walletAccount, supportAccount...) client := setupClient(t, ctx, walletAccount, supportAccount, walletEvent) { - ctx := jwtclient.CtxWithTokenLocation(ctx, "127.1.1.1") + ctx := core.CtxWithTokenLocation(ctx, "127.1.1.1") // stm: @VENUSGATEWAY_WALLET_EVENT_LISTEN_WALLET_EVENT_002 err := client.walletEventClient.listenWalletRequestOnce(ctx) require.Error(t, err) @@ -105,7 +105,7 @@ func TestSupportNewAccount(t *testing.T) { err = client.walletEventClient.SupportAccount(ctx, "fake_acc") require.EqualError(t, err, "unable to get account name in method SupportNewAccount request") - ctx = jwtclient.CtxWithName(ctx, "fac_acc") + ctx = core.CtxWithName(ctx, "fac_acc") err = client.walletEventClient.SupportAccount(ctx, "__") require.NoError(t, err) @@ -133,13 +133,13 @@ func TestAddNewAddress(t *testing.T) { err := client.walletEventClient.AddNewAddress(ctx, []address.Address{addr1}) require.EqualError(t, err, "unable to get account name in method AddNewAddress request") - ctx = jwtclient.CtxWithName(ctx, "incorrect wallet account") + ctx = core.CtxWithName(ctx, "incorrect wallet account") // wallet connection info not found // stm: @VENUSGATEWAY_WALLET_EVENT_ADD_NEW_ADDRESS_003 err = client.walletEventClient.AddNewAddress(ctx, []address.Address{addr1}) require.Error(t, err) - ctx = jwtclient.CtxWithName(ctx, walletAccount) + ctx = core.CtxWithName(ctx, walletAccount) // stm: @VENUSGATEWAY_WALLET_EVENT_ADD_NEW_ADDRESS_004 client.wallet.SetFail(ctx, true) // verify address failed @@ -151,11 +151,11 @@ func TestAddNewAddress(t *testing.T) { err = client.walletEventClient.AddNewAddress(ctx, []address.Address{addr1}) require.NoError(t, err) - ctx = jwtclient.CtxWithName(ctx, walletAccount) + ctx = core.CtxWithName(ctx, walletAccount) err = client.walletEventClient.AddNewAddress(ctx, []address.Address{addr1}) // allow dup add require.NoError(t, err) - ctx = jwtclient.CtxWithName(ctx, walletAccount) + ctx = core.CtxWithName(ctx, walletAccount) err = client.walletEventClient.AddNewAddress(ctx, []address.Address{addr1, addr1, addr2}) require.NoError(t, err) @@ -178,7 +178,7 @@ func TestRemoveNewAddressAndWalletHas(t *testing.T) { client.walletEventClient.WaitReady(ctx) addr1 := client.newkey() - accCtx := jwtclient.CtxWithName(ctx, walletAccount) + accCtx := core.CtxWithName(ctx, walletAccount) err := client.walletEventClient.AddNewAddress(accCtx, []address.Address{addr1}) require.NoError(t, err) has, err := walletEvent.WalletHas(ctx, addr1, []string{walletAccount}) @@ -328,14 +328,14 @@ func (m *mockClient) newkey() address.Address { } func (m *mockClient) listenWalletEvent(ctx context.Context) { - ctx = jwtclient.CtxWithTokenLocation(ctx, "127.1.1.1") - ctx = jwtclient.CtxWithName(ctx, m.walletAccount) + ctx = core.CtxWithTokenLocation(ctx, "127.1.1.1") + ctx = core.CtxWithName(ctx, m.walletAccount) m.walletEventClient.ListenWalletRequest(ctx) } func (m *mockClient) supportNewAccount(ctx context.Context, account string) error { - ctx = jwtclient.CtxWithTokenLocation(ctx, "127.1.1.1") - ctx = jwtclient.CtxWithName(ctx, m.walletAccount) + ctx = core.CtxWithTokenLocation(ctx, "127.1.1.1") + ctx = core.CtxWithName(ctx, m.walletAccount) return m.walletEventClient.SupportAccount(ctx, account) }