Skip to content

Commit

Permalink
Add kyb to kyc verified check, add tests, update caminogo dependency (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
evlekht authored Jul 25, 2024
1 parent 6ddf0fe commit 9ffb0e2
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 9 deletions.
54 changes: 54 additions & 0 deletions core/admin/camino_mock_state.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions eth/ethadmin/camino_ethadmin.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ var (
)

const (
KYC_VERIFIED = 1
KYC_EXPIRED = 2
NOT_VERIFIED = 0b0000 // 0
KYC_VERIFIED = 0b0001 // 1, bit 0
KYC_EXPIRED = 0b0010 // 2, bit 1
KYB_VERIFIED = 0b1000 // 8, bit 3

VERIFIED = KYC_VERIFIED | KYB_VERIFIED
)

type AdminControllerBackend interface {
Expand Down Expand Up @@ -139,16 +143,18 @@ func (a *AdminController) GetFixedBaseFee(head *types.Header, state admin.StateD

func (a *AdminController) KycVerified(head *types.Header, state admin.StateDB, addr common.Address) bool {
if a.cfg.IsSunrisePhase0(head.Time) {
// Calculate storage position
storagePos := crypto.Keccak256Hash(append(addr.Hash().Bytes(), common.HexToHash("0x2").Bytes()...))
// Get the KYC states
kycStates := new(big.Int).SetBytes(state.GetState(contractAddr, storagePos).Bytes()).Uint64()
kycStates := new(big.Int).SetBytes(state.GetState(contractAddr, kycStoragePosition(addr)).Bytes()).Uint64()
// Return true if KYC flag is set
return (kycStates & KYC_VERIFIED) != 0
return (kycStates & VERIFIED) != 0
}
return true
}

func (a *AdminController) inScanRange(head *types.Header) bool {
return head.Number.Cmp(&a.lastChangeHeight) >= 0 && head.Number.Cmp(&a.scanHeight) <= 0
}

func kycStoragePosition(addr common.Address) common.Hash {
return crypto.Keccak256Hash(append(addr.Hash().Bytes(), common.HexToHash("0x2").Bytes()...))
}
74 changes: 74 additions & 0 deletions eth/ethadmin/camino_ethadmin_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package ethadmin

import (
"math/big"
"testing"

"github.com/ava-labs/coreth/core/admin"
"github.com/ava-labs/coreth/core/types"
"github.com/ava-labs/coreth/params"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)

func TestKycVerified(t *testing.T) {
address := common.Address{1}
sunriseTimestamp := uint64(1000)
sunriseActiveHeader := &types.Header{
Time: sunriseTimestamp,
}

adminCtrl := NewController(nil, &params.ChainConfig{
SunrisePhase0BlockTimestamp: &sunriseTimestamp,
})

tests := map[string]struct {
stateDB func(c *gomock.Controller) *admin.MockStateDB
header *types.Header
address common.Address
expectedResult bool
}{
"Not verified": {
stateDB: func(c *gomock.Controller) *admin.MockStateDB {
stateDB := admin.NewMockStateDB(c)
stateDB.EXPECT().GetState(contractAddr, kycStoragePosition(address)).
Return(common.BigToHash(big.NewInt(NOT_VERIFIED)))
return stateDB
},
header: sunriseActiveHeader,
address: address,
expectedResult: false,
},
"KYC verified": {
stateDB: func(c *gomock.Controller) *admin.MockStateDB {
stateDB := admin.NewMockStateDB(c)
stateDB.EXPECT().GetState(contractAddr, kycStoragePosition(address)).
Return(common.BigToHash(big.NewInt(KYC_VERIFIED)))
return stateDB
},
header: sunriseActiveHeader,
address: address,
expectedResult: true,
},
"KYB verified": {
stateDB: func(c *gomock.Controller) *admin.MockStateDB {
stateDB := admin.NewMockStateDB(c)
stateDB.EXPECT().GetState(contractAddr, kycStoragePosition(address)).
Return(common.BigToHash(big.NewInt(KYB_VERIFIED)))
return stateDB
},
header: sunriseActiveHeader,
address: address,
expectedResult: true,
},
}

for name, tt := range tests {
t.Run(name, func(t *testing.T) {
c := gomock.NewController(t)
result := adminCtrl.KycVerified(tt.header, tt.stateDB(c), tt.address)
require.Equal(t, tt.expectedResult, result)
})
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,6 @@ require (
rsc.io/tmplfunc v0.0.3 // indirect
)

replace github.com/ava-labs/avalanchego => github.com/chain4travel/caminogo v1.1.15-rc0
replace github.com/ava-labs/avalanchego => github.com/chain4travel/caminogo v1.1.15-rc2

replace github.com/ava-labs/avalanche-ledger-go => github.com/chain4travel/camino-ledger-go v0.0.13-c4t
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/chain4travel/caminogo v1.1.15-rc0 h1:BNW0FOTRozQiiTJOdo33yRRYdQHgwDxwJHKIf5qqcX0=
github.com/chain4travel/caminogo v1.1.15-rc0/go.mod h1:TgxFs36paYCdRnTcZ5tSg4bXvLMrb6ib45Spysrbdxc=
github.com/chain4travel/caminogo v1.1.15-rc2 h1:QzxhXDa2Ozq/klfslb6SGkzM4BvgPaepyEHa0TsMHjA=
github.com/chain4travel/caminogo v1.1.15-rc2/go.mod h1:YWdA9uLuJhl52XZidSITIYaSuzJi1xvDCp2IAQIzt+U=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/logex v1.2.0/go.mod h1:9+9sk7u7pGNWYMkh0hdiL++6OeibzJccyQU4p4MedaY=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
Expand Down

0 comments on commit 9ffb0e2

Please sign in to comment.