From 68e23ba19c6b71eced414f4d21954c4e84e49043 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Levente=20T=C3=B3th?= Date: Thu, 5 Oct 2023 19:19:34 +0200 Subject: [PATCH] refactor: uint64 to uint32 --- pkg/api/api_test.go | 2 +- pkg/storageincentives/agent.go | 2 +- pkg/storageincentives/agent_test.go | 2 +- pkg/storageincentives/redistribution/redistribution.go | 6 +++--- .../redistribution/redistribution_test.go | 8 ++++---- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/api/api_test.go b/pkg/api/api_test.go index a2318ef2fae..53309f1d63e 100644 --- a/pkg/api/api_test.go +++ b/pkg/api/api_test.go @@ -791,7 +791,7 @@ func (m *mockContract) Claim(context.Context, []redistribution.Proof) (common.Ha return common.Hash{}, nil } -func (m *mockContract) Commit(context.Context, []byte, uint64) (common.Hash, error) { +func (m *mockContract) Commit(context.Context, []byte, uint32) (common.Hash, error) { m.mtx.Lock() defer m.mtx.Unlock() m.callsList = append(m.callsList, commitCall) diff --git a/pkg/storageincentives/agent.go b/pkg/storageincentives/agent.go index 850f16c994e..a0669e97875 100644 --- a/pkg/storageincentives/agent.go +++ b/pkg/storageincentives/agent.go @@ -450,7 +450,7 @@ func (a *Agent) commit(ctx context.Context, sample sampler.Data, round uint64) e return err } - txHash, err := a.contract.Commit(ctx, obfuscatedHash, uint64(round)) + txHash, err := a.contract.Commit(ctx, obfuscatedHash, uint32(round)) if err != nil { a.metrics.ErrCommit.Inc() return err diff --git a/pkg/storageincentives/agent_test.go b/pkg/storageincentives/agent_test.go index e8fafcef67a..d0951479789 100644 --- a/pkg/storageincentives/agent_test.go +++ b/pkg/storageincentives/agent_test.go @@ -261,7 +261,7 @@ func (m *mockContract) Claim(context.Context, []redistribution.Proof) (common.Ha return common.Hash{}, nil } -func (m *mockContract) Commit(context.Context, []byte, uint64) (common.Hash, error) { +func (m *mockContract) Commit(context.Context, []byte, uint32) (common.Hash, error) { m.mtx.Lock() defer m.mtx.Unlock() m.callsList = append(m.callsList, commitCall) diff --git a/pkg/storageincentives/redistribution/redistribution.go b/pkg/storageincentives/redistribution/redistribution.go index 91dfa9ba83c..f803704cffe 100644 --- a/pkg/storageincentives/redistribution/redistribution.go +++ b/pkg/storageincentives/redistribution/redistribution.go @@ -24,7 +24,7 @@ type Contract interface { IsPlaying(context.Context, uint8) (bool, error) IsWinner(context.Context) (bool, error) Claim(context.Context, []Proof) (common.Hash, error) - Commit(context.Context, []byte, uint64) (common.Hash, error) + Commit(context.Context, []byte, uint32) (common.Hash, error) Reveal(context.Context, uint8, []byte, []byte) (common.Hash, error) } @@ -93,7 +93,7 @@ func (c *contract) IsWinner(ctx context.Context) (isWinner bool, err error) { // Claim sends a transaction to blockchain if a win is claimed. func (c *contract) Claim(ctx context.Context, proofs []Proof) (common.Hash, error) { - callData, err := c.incentivesContractABI.Pack("claim", proofs) + callData, err := c.incentivesContractABI.Pack("claim", proofs[0], proofs[1], proofs[2]) if err != nil { return common.Hash{}, err } @@ -115,7 +115,7 @@ func (c *contract) Claim(ctx context.Context, proofs []Proof) (common.Hash, erro } // Commit submits the obfusHash hash by sending a transaction to the blockchain. -func (c *contract) Commit(ctx context.Context, obfusHash []byte, round uint64) (common.Hash, error) { +func (c *contract) Commit(ctx context.Context, obfusHash []byte, round uint32) (common.Hash, error) { callData, err := c.incentivesContractABI.Pack("commit", common.BytesToHash(obfusHash), common.BytesToHash(c.overlay.Bytes()), round) if err != nil { return common.Hash{}, err diff --git a/pkg/storageincentives/redistribution/redistribution_test.go b/pkg/storageincentives/redistribution/redistribution_test.go index 5b0669efe1c..319cc2fa66f 100644 --- a/pkg/storageincentives/redistribution/redistribution_test.go +++ b/pkg/storageincentives/redistribution/redistribution_test.go @@ -276,7 +276,7 @@ func TestRedistribution(t *testing.T) { var obfus [32]byte testobfus := common.Hex2Bytes("hash") copy(obfus[:], testobfus) - expectedCallData, err := redistributionContractABI.Pack("commit", obfus, common.BytesToHash(owner.Bytes()), uint64(0)) + expectedCallData, err := redistributionContractABI.Pack("commit", obfus, common.BytesToHash(owner.Bytes()), uint32(0)) if err != nil { t.Fatal(err) } @@ -306,7 +306,7 @@ func TestRedistribution(t *testing.T) { redistributionContractABI, ) - _, err = contract.Commit(ctx, testobfus, uint64(0)) + _, err = contract.Commit(ctx, testobfus, uint32(0)) if err != nil { t.Fatal(err) } @@ -411,7 +411,7 @@ func TestRedistribution(t *testing.T) { t.Run("invalid call data", func(t *testing.T) { t.Parallel() - expectedCallData, err := redistributionContractABI.Pack("commit", common.BytesToHash(common.Hex2Bytes("some hash")), common.BytesToHash(common.Hex2Bytes("some address")), uint64(0)) + expectedCallData, err := redistributionContractABI.Pack("commit", common.BytesToHash(common.Hex2Bytes("some hash")), common.BytesToHash(common.Hex2Bytes("some address")), uint32(0)) if err != nil { t.Fatal(err) } @@ -433,7 +433,7 @@ func TestRedistribution(t *testing.T) { redistributionContractABI, ) - _, err = contract.Commit(ctx, common.Hex2Bytes("hash"), uint64(0)) + _, err = contract.Commit(ctx, common.Hex2Bytes("hash"), uint32(0)) if err == nil { t.Fatal("expected error") }