From 66e95e047344283042f140e7e682d0f4a6e88d2c Mon Sep 17 00:00:00 2001 From: ice-cronus <105345303+ice-cronus@users.noreply.github.com> Date: Mon, 15 Jul 2024 17:02:00 +0300 Subject: [PATCH 1/5] load balance social kyc based on kyc config --- go.mod | 14 +++++++------- go.sum | 28 ++++++++++++++-------------- tokenomics/contract.go | 20 ++++++++++++-------- tokenomics/kyc.go | 25 +++++++++++++++++++++---- 4 files changed, 54 insertions(+), 33 deletions(-) diff --git a/go.mod b/go.mod index fb3c4b5..6f33566 100644 --- a/go.mod +++ b/go.mod @@ -10,14 +10,14 @@ require ( github.com/ethereum/go-ethereum v1.14.6 github.com/goccy/go-json v0.10.3 github.com/hashicorp/go-multierror v1.1.1 - github.com/ice-blockchain/eskimo v1.369.0 + github.com/ice-blockchain/eskimo v1.371.0 github.com/ice-blockchain/go-tarantool-client v0.0.0-20230327200757-4fc71fa3f7bb - github.com/ice-blockchain/wintr v1.144.0 + github.com/ice-blockchain/wintr v1.145.0 github.com/imroc/req/v3 v3.43.7 github.com/oklog/ulid/v2 v2.1.0 github.com/pkg/errors v0.9.1 github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 - github.com/redis/go-redis/v9 v9.5.3 + github.com/redis/go-redis/v9 v9.5.4 github.com/stretchr/testify v1.9.0 github.com/swaggo/swag v1.16.3 github.com/testcontainers/testcontainers-go v0.32.0 @@ -27,7 +27,7 @@ require ( require ( cloud.google.com/go v0.115.0 // indirect - cloud.google.com/go/auth v0.7.0 // indirect + cloud.google.com/go/auth v0.7.1 // indirect cloud.google.com/go/auth/oauth2adapt v0.2.3 // indirect cloud.google.com/go/compute/metadata v0.5.0 // indirect cloud.google.com/go/firestore v1.15.0 // indirect @@ -211,9 +211,9 @@ require ( golang.org/x/tools v0.23.0 // indirect google.golang.org/api v0.188.0 // indirect google.golang.org/appengine/v2 v2.0.6 // indirect - google.golang.org/genproto v0.0.0-20240709173604-40e1e62336c5 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20240709173604-40e1e62336c5 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5 // indirect + google.golang.org/genproto v0.0.0-20240711142825-46eb208f015d // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d // indirect google.golang.org/grpc v1.65.0 // indirect google.golang.org/protobuf v1.34.2 // indirect gopkg.in/ini.v1 v1.67.0 // indirect diff --git a/go.sum b/go.sum index 061b136..a8c4966 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.115.0 h1:CnFSK6Xo3lDYRoBKEcAtia6VSC837/ZkJuRduSFnr14= cloud.google.com/go v0.115.0/go.mod h1:8jIM5vVgoAEoiVxQ/O4BFTfHqulPZgs/ufEzMcFMdWU= -cloud.google.com/go/auth v0.7.0 h1:kf/x9B3WTbBUHkC+1VS8wwwli9TzhSt0vSTVBmMR8Ts= -cloud.google.com/go/auth v0.7.0/go.mod h1:D+WqdrpcjmiCgWrXmLLxOVq1GACoE36chW6KXoEvuIw= +cloud.google.com/go/auth v0.7.1 h1:Iv1bbpzJ2OIg16m94XI9/tlzZZl3cdeR3nGVGj78N7s= +cloud.google.com/go/auth v0.7.1/go.mod h1:VEc4p5NNxycWQTMQEDQF0bd6aTMb6VgYDXEwiJJQAbs= cloud.google.com/go/auth/oauth2adapt v0.2.3 h1:MlxF+Pd3OmSudg/b1yZ5lJwoXCEaeedAguodky1PcKI= cloud.google.com/go/auth/oauth2adapt v0.2.3/go.mod h1:tMQXOfZzFuNuUxOypHlQEXgdfX5cuhwU+ffUuXRJE8I= cloud.google.com/go/compute/metadata v0.5.0 h1:Zr0eK8JbFv6+Wi4ilXAR8FJ3wyNdpxHKJNPos6LTZOY= @@ -300,12 +300,12 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc= github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= -github.com/ice-blockchain/eskimo v1.369.0 h1:DFguku6xR4rb8G1Ay4LAh0s6qzYPnoKsO28uFJGvAko= -github.com/ice-blockchain/eskimo v1.369.0/go.mod h1:l4MZKGo/Lpq+LFr65HUAGc/SvN4IclA0kpFqXjjQsZ8= +github.com/ice-blockchain/eskimo v1.371.0 h1:o9acbUNUZ80U7CLyzrQyd2T67O/92+a8jiut3BtTpV0= +github.com/ice-blockchain/eskimo v1.371.0/go.mod h1:7m6dFwOIi3aSAdPBJa2nJKjaEr1QDXXDVs4D3w+m7c4= github.com/ice-blockchain/go-tarantool-client v0.0.0-20230327200757-4fc71fa3f7bb h1:8TnFP3mc7O+tc44kv2e0/TpZKnEVUaKH+UstwfBwRkk= github.com/ice-blockchain/go-tarantool-client v0.0.0-20230327200757-4fc71fa3f7bb/go.mod h1:ZsQU7i3mxhgBBu43Oev7WPFbIjP4TniN/b1UPNGbrq8= -github.com/ice-blockchain/wintr v1.144.0 h1:YQE0olkPdSI6AOlw7r/j5jGI6uLciZQrvXFIkN4C4l4= -github.com/ice-blockchain/wintr v1.144.0/go.mod h1:3HAl5nodsetqQN30q3gUvsxgfq2B7F86Os/II7/5GPQ= +github.com/ice-blockchain/wintr v1.145.0 h1:ObAgnS2Mqc2tbSM1pRpmi4dGUtkD/T+lacpaq+Ri8Mw= +github.com/ice-blockchain/wintr v1.145.0/go.mod h1:CgbY1UEyIx//+tM57Hz72Jd28UOs5tpOlJOByyQhi2c= github.com/imroc/req/v3 v3.43.7 h1:dOcNb9n0X83N5/5/AOkiU+cLhzx8QFXjv5MhikazzQA= github.com/imroc/req/v3 v3.43.7/go.mod h1:SQIz5iYop16MJxbo8ib+4LnostGCok8NQf8ToyQc2xA= github.com/ip2location/ip2location-go/v9 v9.7.0 h1:ipwl67HOWcrw+6GOChkEXcreRQR37NabqBd2ayYa4Q0= @@ -440,8 +440,8 @@ github.com/quic-go/quic-go v0.45.1 h1:tPfeYCk+uZHjmDRwHHQmvHRYL2t44ROTujLeFVBmjC github.com/quic-go/quic-go v0.45.1/go.mod h1:1dLehS7TIR64+vxGR70GDcatWTOtMX2PUtnKsjbTurI= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= -github.com/redis/go-redis/v9 v9.5.3 h1:fOAp1/uJG+ZtcITgZOfYFmTKPE7n4Vclj1wZFgRciUU= -github.com/redis/go-redis/v9 v9.5.3/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M= +github.com/redis/go-redis/v9 v9.5.4 h1:vOFYDKKVgrI5u++QvnMT7DksSMYg7Aw/Np4vLJLKLwY= +github.com/redis/go-redis/v9 v9.5.4/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M= github.com/refraction-networking/utls v1.6.7 h1:zVJ7sP1dJx/WtVuITug3qYUq034cDq9B2MR1K67ULZM= github.com/refraction-networking/utls v1.6.7/go.mod h1:BC3O4vQzye5hqpmDTWUqi4P5DDhzJfkV1tdqtawQIH0= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= @@ -685,12 +685,12 @@ google.golang.org/appengine/v2 v2.0.6/go.mod h1:WoEXGoXNfa0mLvaH5sV3ZSGXwVmy8yf7 google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20240709173604-40e1e62336c5 h1:ORprMx6Xqr56pGwKXMnVEFBI0k7OIcHI0Rx92/rKypo= -google.golang.org/genproto v0.0.0-20240709173604-40e1e62336c5/go.mod h1:FfBgJBJg9GcpPvKIuHSZ/aE1g2ecGL74upMzGZjiGEY= -google.golang.org/genproto/googleapis/api v0.0.0-20240709173604-40e1e62336c5 h1:a/Z0jgw03aJ2rQnp5PlPpznJqJft0HyvyrcUcxgzPwY= -google.golang.org/genproto/googleapis/api v0.0.0-20240709173604-40e1e62336c5/go.mod h1:mw8MG/Qz5wfgYr6VqVCiZcHe/GJEfI+oGGDCohaVgB0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5 h1:SbSDUWW1PAO24TNpLdeheoYPd7kllICcLU52x6eD4kQ= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY= +google.golang.org/genproto v0.0.0-20240711142825-46eb208f015d h1:/hmn0Ku5kWij/kjGsrcJeC1T/MrJi2iNWwgAqrihFwc= +google.golang.org/genproto v0.0.0-20240711142825-46eb208f015d/go.mod h1:FfBgJBJg9GcpPvKIuHSZ/aE1g2ecGL74upMzGZjiGEY= +google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d h1:kHjw/5UfflP/L5EbledDrcG4C2597RtymmGRZvHiCuY= +google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d/go.mod h1:mw8MG/Qz5wfgYr6VqVCiZcHe/GJEfI+oGGDCohaVgB0= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d h1:JU0iKnSg02Gmb5ZdV8nYsKEKsP6o/FGVWTrw4i1DA9A= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= diff --git a/tokenomics/contract.go b/tokenomics/contract.go index 9b64e80..e94e0db 100644 --- a/tokenomics/contract.go +++ b/tokenomics/contract.go @@ -338,10 +338,12 @@ type ( Enabled bool `json:"enabled"` } `json:"face-auth"` Social1KYC struct { - DisabledVersions []string `json:"disabledVersions"` - ForceKYCForUserIds []string `json:"forceKYCForUserIds"` - EnabledMobile bool `json:"enabledMobile"` - EnabledWeb bool `json:"enabledWeb"` + DisabledVersions []string `json:"disabledVersions"` + ForceKYCForUserIds []string `json:"forceKYCForUserIds"` + EnabledMobile bool `json:"enabledMobile"` + EnabledWeb bool `json:"enabledWeb"` + StartDate *time.Time `json:"startDate"` + Duration stdlibtime.Duration `json:"duration"` } `json:"social1-kyc"` QuizKYC struct { DisabledVersions []string `json:"disabledVersions"` @@ -349,10 +351,12 @@ type ( Enabled bool `json:"enabled"` } `json:"quiz-kyc"` Social2KYC struct { - DisabledVersions []string `json:"disabledVersions"` - ForceKYCForUserIds []string `json:"forceKYCForUserIds"` - EnabledMobile bool `json:"enabledMobile"` - EnabledWeb bool `json:"enabledWeb"` + DisabledVersions []string `json:"disabledVersions"` + ForceKYCForUserIds []string `json:"forceKYCForUserIds"` + EnabledMobile bool `json:"enabledMobile"` + EnabledWeb bool `json:"enabledWeb"` + StartDate *time.Time `json:"startDate"` + Duration stdlibtime.Duration `json:"duration"` } `json:"social2-kyc"` WebFaceAuth struct { Enabled bool `json:"enabled"` diff --git a/tokenomics/kyc.go b/tokenomics/kyc.go index 752c05f..136ac15 100644 --- a/tokenomics/kyc.go +++ b/tokenomics/kyc.go @@ -133,16 +133,16 @@ func (r *repository) checkNextKYCStep(ctx context.Context, state *getCurrentMini } switch state.KYCStepPassed { case users.NoneKYCStep: - social1Required := state.KYCStepNotAttempted(users.Social1KYCStep) || state.DelayPassedSinceLastKYCStepAttempt(users.Social1KYCStep, r.cfg.KYC.Social1Delay) //nolint:lll + social1Required := (state.KYCStepNotAttempted(users.Social1KYCStep) && r.userLoadBalancedForKYC(users.Social1KYCStep, state.ID)) || state.DelayPassedSinceLastKYCStepAttempt(users.Social1KYCStep, r.cfg.KYC.Social1Delay) //nolint:lll - if r.isKYCStepForced(users.Social1KYCStep, state.UserID) || (!state.MiningSessionSoloLastStartedAt.IsNil() && social1Required && r.isKYCEnabled(ctx, state.LatestDevice, users.Social1KYCStep)) { //nolint:lll // . + if r.isKYCStepForced(users.Social1KYCStep, state.UserID) || (!state.MiningSessionSoloLastStartedAt.IsNil() && (social1Required && r.isKYCEnabled(ctx, state.LatestDevice, users.Social1KYCStep))) { //nolint:lll // . return terror.New(ErrKYCRequired, map[string]any{ "kycSteps": []users.KYCStep{users.Social1KYCStep}, }) } case users.FacialRecognitionKYCStep: case users.LivenessDetectionKYCStep: - social1Required := (state.KYCStepAttempted(users.Social1KYCStep-1) && state.KYCStepNotAttempted(users.Social1KYCStep)) || //nolint:lll // . + social1Required := (state.KYCStepAttempted(users.Social1KYCStep-1) && state.KYCStepNotAttempted(users.Social1KYCStep) && r.userLoadBalancedForKYC(users.Social1KYCStep, state.ID)) || //nolint:lll // . state.DelayPassedSinceLastKYCStepAttempt(users.Social1KYCStep, r.cfg.KYC.Social1Delay) minDelaySinceLastLiveness := state.DelayPassedSinceLastKYCStepAttempt(users.LivenessDetectionKYCStep, r.cfg.MiningSessionDuration.Min) @@ -153,7 +153,7 @@ func (r *repository) checkNextKYCStep(ctx context.Context, state *getCurrentMini } case users.Social1KYCStep: case users.QuizKYCStep: - social2Required := (state.KYCStepAttempted(users.Social2KYCStep-1) && state.KYCStepNotAttempted(users.Social2KYCStep)) || + social2Required := (state.KYCStepAttempted(users.Social2KYCStep-1) && state.KYCStepNotAttempted(users.Social2KYCStep) && r.userLoadBalancedForKYC(users.Social2KYCStep, state.ID)) || state.DelayPassedSinceLastKYCStepAttempt(users.Social2KYCStep, r.cfg.KYC.Social2Delay) minDelaySinceLastKYCStep := state.DelayPassedSinceLastKYCStepAttempt(users.Social2KYCStep-1, r.cfg.MiningSessionDuration.Min) @@ -178,6 +178,23 @@ func (r *repository) checkNextKYCStep(ctx context.Context, state *getCurrentMini return nil } +func (r *repository) userLoadBalancedForKYC(kycStep users.KYCStep, userID int64) bool { + var startDate *time.Time + var lbDuration stdlibtime.Duration + if cfgVal := r.cfg.kycConfigJSON.Load(); cfgVal != nil { + switch kycStep { + case users.Social1KYCStep: + startDate = cfgVal.Social1KYC.StartDate + lbDuration = cfgVal.Social1KYC.Duration + case users.Social2KYCStep: + startDate = cfgVal.Social2KYC.StartDate + lbDuration = cfgVal.Social2KYC.Duration + } + } + + return startDate == nil || lbDuration == 0 || (time.Now().After(*startDate.Time) && time.Now().Sub(*startDate.Time) <= lbDuration && int64(time.Now().Sub(*startDate.Time)%(lbDuration/r.cfg.MiningSessionDuration.Max)) >= userID%int64(lbDuration/r.cfg.MiningSessionDuration.Max)) +} + func (r *repository) isLastKYCStep(kycStep users.KYCStep) bool { lastKYCStep := users.Social2KYCStep if kycConfig := r.cfg.kycConfigJSON.Load(); kycConfig != nil { From 4c8cf5b127f1084614c6a422199fe495a8b5bf75 Mon Sep 17 00:00:00 2001 From: ice-cronus <105345303+ice-cronus@users.noreply.github.com> Date: Mon, 15 Jul 2024 17:10:40 +0300 Subject: [PATCH 2/5] remove extra now check from load balance to avoid expiration for new upcoming users in the future --- tokenomics/kyc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tokenomics/kyc.go b/tokenomics/kyc.go index 136ac15..c93382f 100644 --- a/tokenomics/kyc.go +++ b/tokenomics/kyc.go @@ -192,7 +192,7 @@ func (r *repository) userLoadBalancedForKYC(kycStep users.KYCStep, userID int64) } } - return startDate == nil || lbDuration == 0 || (time.Now().After(*startDate.Time) && time.Now().Sub(*startDate.Time) <= lbDuration && int64(time.Now().Sub(*startDate.Time)%(lbDuration/r.cfg.MiningSessionDuration.Max)) >= userID%int64(lbDuration/r.cfg.MiningSessionDuration.Max)) + return startDate == nil || lbDuration == 0 || (time.Now().After(*startDate.Time) && int64(time.Now().Sub(*startDate.Time)%(lbDuration/r.cfg.MiningSessionDuration.Max)) >= userID%int64(lbDuration/r.cfg.MiningSessionDuration.Max)) } func (r *repository) isLastKYCStep(kycStep users.KYCStep) bool { From db7b7b4d061f25c8e853566b7024a27b4b54f063 Mon Sep 17 00:00:00 2001 From: ice-cronus <105345303+ice-cronus@users.noreply.github.com> Date: Mon, 15 Jul 2024 17:26:00 +0300 Subject: [PATCH 3/5] fix condition to handle expired and not started case --- tokenomics/kyc.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tokenomics/kyc.go b/tokenomics/kyc.go index c93382f..1662d52 100644 --- a/tokenomics/kyc.go +++ b/tokenomics/kyc.go @@ -192,7 +192,8 @@ func (r *repository) userLoadBalancedForKYC(kycStep users.KYCStep, userID int64) } } - return startDate == nil || lbDuration == 0 || (time.Now().After(*startDate.Time) && int64(time.Now().Sub(*startDate.Time)%(lbDuration/r.cfg.MiningSessionDuration.Max)) >= userID%int64(lbDuration/r.cfg.MiningSessionDuration.Max)) + return startDate == nil || lbDuration == 0 || time.Now().After(startDate.Add(lbDuration)) || time.Now().Before(*startDate.Time) || + (time.Now().After(*startDate.Time) && int64(time.Now().Sub(*startDate.Time)%(lbDuration/r.cfg.MiningSessionDuration.Max)) >= userID%int64(lbDuration/r.cfg.MiningSessionDuration.Max)) } func (r *repository) isLastKYCStep(kycStep users.KYCStep) bool { From d9b648890170f4f85f9d29b4bb6538ec5d952caf Mon Sep 17 00:00:00 2001 From: ice-cronus <105345303+ice-cronus@users.noreply.github.com> Date: Mon, 15 Jul 2024 18:06:49 +0300 Subject: [PATCH 4/5] fix condition, basic unit test for load balancing --- tokenomics/kyc.go | 8 ++++++-- tokenomics/kyc_test.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 tokenomics/kyc_test.go diff --git a/tokenomics/kyc.go b/tokenomics/kyc.go index 1662d52..38d06ab 100644 --- a/tokenomics/kyc.go +++ b/tokenomics/kyc.go @@ -192,8 +192,12 @@ func (r *repository) userLoadBalancedForKYC(kycStep users.KYCStep, userID int64) } } - return startDate == nil || lbDuration == 0 || time.Now().After(startDate.Add(lbDuration)) || time.Now().Before(*startDate.Time) || - (time.Now().After(*startDate.Time) && int64(time.Now().Sub(*startDate.Time)%(lbDuration/r.cfg.MiningSessionDuration.Max)) >= userID%int64(lbDuration/r.cfg.MiningSessionDuration.Max)) + return loadBalanceKYC(time.Now(), startDate, lbDuration, r.cfg.MiningSessionDuration.Max, userID) +} + +func loadBalanceKYC(now, startDate *time.Time, lbDuration, miningDuration stdlibtime.Duration, userID int64) bool { + return startDate == nil || lbDuration == 0 || now.After(startDate.Add(lbDuration)) || now.Before(*startDate.Time) || + (now.After(*startDate.Time) && int64(now.Sub(*startDate.Time)%(miningDuration)) >= userID%int64(lbDuration/miningDuration)) } func (r *repository) isLastKYCStep(kycStep users.KYCStep) bool { diff --git a/tokenomics/kyc_test.go b/tokenomics/kyc_test.go new file mode 100644 index 0000000..016bcda --- /dev/null +++ b/tokenomics/kyc_test.go @@ -0,0 +1,31 @@ +package tokenomics + +import ( + "github.com/ice-blockchain/wintr/time" + "github.com/stretchr/testify/assert" + "testing" + stdlibtime "time" +) + +func TestLoadBalanceKYCUsers(t *testing.T) { + now := time.Now() + startDate := time.New(now.Add(-1 * stdlibtime.Minute)) + duration := 10 * stdlibtime.Minute + miningDuration := 1 * stdlibtime.Minute + assert.True(t, loadBalanceKYC(now, startDate, duration, miningDuration, 0)) + assert.False(t, loadBalanceKYC(now, startDate, duration, miningDuration, 1)) + assert.False(t, loadBalanceKYC(now, startDate, duration, miningDuration, 2)) + assert.False(t, loadBalanceKYC(now, startDate, duration, miningDuration, 3)) + assert.False(t, loadBalanceKYC(now, startDate, duration, miningDuration, 4)) + assert.False(t, loadBalanceKYC(now, startDate, duration, miningDuration, 5)) + assert.False(t, loadBalanceKYC(now, startDate, duration, miningDuration, 6)) + assert.False(t, loadBalanceKYC(now, startDate, duration, miningDuration, 7)) + assert.False(t, loadBalanceKYC(now, startDate, duration, miningDuration, 8)) + assert.False(t, loadBalanceKYC(now, startDate, duration, miningDuration, 9)) + assert.True(t, loadBalanceKYC(now, startDate, duration, miningDuration, 10)) + assert.False(t, loadBalanceKYC(now, startDate, duration, miningDuration, 11)) + assert.True(t, loadBalanceKYC(time.New(now.Add(2*stdlibtime.Second)), startDate, duration, miningDuration, 12)) + assert.True(t, loadBalanceKYC(time.New(now.Add(3*stdlibtime.Second)), startDate, duration, miningDuration, 13)) + assert.True(t, loadBalanceKYC(time.New(now.Add(4*stdlibtime.Second)), startDate, duration, miningDuration, 14)) + assert.True(t, loadBalanceKYC(time.New(now.Add(4*stdlibtime.Second)), startDate, duration, miningDuration, 24)) +} From c962a641489f0b64b277653bc969158fba9f3fb0 Mon Sep 17 00:00:00 2001 From: ice-cronus <105345303+ice-cronus@users.noreply.github.com> Date: Mon, 15 Jul 2024 18:10:04 +0300 Subject: [PATCH 5/5] fix licensing --- tokenomics/kyc_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tokenomics/kyc_test.go b/tokenomics/kyc_test.go index 016bcda..07b02fe 100644 --- a/tokenomics/kyc_test.go +++ b/tokenomics/kyc_test.go @@ -1,10 +1,14 @@ +// SPDX-License-Identifier: ice License 1.0 + package tokenomics import ( - "github.com/ice-blockchain/wintr/time" - "github.com/stretchr/testify/assert" "testing" stdlibtime "time" + + "github.com/stretchr/testify/assert" + + "github.com/ice-blockchain/wintr/time" ) func TestLoadBalanceKYCUsers(t *testing.T) {