Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
feat: user registry and cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
alok committed Nov 15, 2023
1 parent 9e2bade commit 6957564
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
32 changes: 32 additions & 0 deletions pkg/contracts/registry/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,36 @@ func TestRegistryContract(t *testing.T) {
t.Fatalf("expected stake amount to be %s, got %s", amount.String(), stakeAmt.String())
}
})

t.Run("CheckUserRegistered", func(t *testing.T) {
registryContractAddr := common.HexToAddress("abcd")
amount := big.NewInt(1000000000000000000)
address := common.HexToAddress("abcdef")

mockClient := mockevmclient.New(
mockevmclient.WithCallFunc(
func(ctx context.Context, req *evmclient.TxRequest) ([]byte, error) {
if req.To.Cmp(registryContractAddr) != 0 {
t.Fatalf(
"expected to address to be %s, got %s",
registryContractAddr.Hex(), req.To.Hex(),
)
}

return amount.FillBytes(make([]byte, 32)), nil
},
),
)

registryContract := registrycontract.New(
registryContractAddr,
mockClient,
util.NewTestLogger(os.Stdout),
)

isRegistered := registryContract.CheckUserRegistered(context.Background(), address)
if !isRegistered {
t.Fatalf("expected user to be registered")
}
})
}
32 changes: 32 additions & 0 deletions pkg/contracts/userregistry/userregistry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,36 @@ func TestUserRegistryContract(t *testing.T) {
t.Fatalf("expected stake amount to be %s, got %s", amount.String(), stakeAmt.String())
}
})

t.Run("CheckUserRegistered", func(t *testing.T) {
registryContractAddr := common.HexToAddress("abcd")
amount := big.NewInt(1000000000000000000)
address := common.HexToAddress("abcdef")

mockClient := mockevmclient.New(
mockevmclient.WithCallFunc(
func(ctx context.Context, req *evmclient.TxRequest) ([]byte, error) {
if req.To.Cmp(registryContractAddr) != 0 {
t.Fatalf(
"expected to address to be %s, got %s",
registryContractAddr.Hex(), req.To.Hex(),
)
}

return amount.FillBytes(make([]byte, 32)), nil
},
),
)

registryContract := userregistrycontract.New(
registryContractAddr,
mockClient,
util.NewTestLogger(os.Stdout),
)

isRegistered := registryContract.CheckUserRegistered(context.Background(), address)
if !isRegistered {
t.Fatal("expected user to be registered")
}
})
}

0 comments on commit 6957564

Please sign in to comment.