Skip to content

Commit

Permalink
feat: refactor contracts functions names and arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
martinconic committed Jul 5, 2024
1 parent 58b62d6 commit d2d3744
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/coreos/go-semver v0.3.0
github.com/ethereum/go-ethereum v1.14.3
github.com/ethersphere/go-price-oracle-abi v0.2.0
github.com/ethersphere/go-storage-incentives-abi v0.8.6
github.com/ethersphere/go-storage-incentives-abi v0.9.0-rc3
github.com/ethersphere/go-sw3-abi v0.6.5
github.com/ethersphere/langos v1.0.0
github.com/go-playground/validator/v10 v10.11.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ github.com/ethereum/go-ethereum v1.14.3 h1:5zvnAqLtnCZrU9uod1JCvHWJbPMURzYFHfc2e
github.com/ethereum/go-ethereum v1.14.3/go.mod h1:1STrq471D0BQbCX9He0hUj4bHxX2k6mt5nOQJhDNOJ8=
github.com/ethersphere/go-price-oracle-abi v0.2.0 h1:wtIcYLgNZHY4BjYwJCnu93SvJdVAZVvBaKinspyyHvQ=
github.com/ethersphere/go-price-oracle-abi v0.2.0/go.mod h1:sI/Qj4/zJ23/b1enzwMMv0/hLTpPNVNacEwCWjo6yBk=
github.com/ethersphere/go-storage-incentives-abi v0.8.6 h1:M9WwEtWoxVHKehBAoPMzQhXlzlBetuXsrGgoFvM5I8Y=
github.com/ethersphere/go-storage-incentives-abi v0.8.6/go.mod h1:SXvJVtM4sEsaSKD0jc1ClpDLw8ErPoROZDme4Wrc/Nc=
github.com/ethersphere/go-storage-incentives-abi v0.9.0-rc3 h1:TCCGtf1jODBUusTiH94Nhgw03apgchQZaJ03L/vt4z4=
github.com/ethersphere/go-storage-incentives-abi v0.9.0-rc3/go.mod h1:SXvJVtM4sEsaSKD0jc1ClpDLw8ErPoROZDme4Wrc/Nc=
github.com/ethersphere/go-sw3-abi v0.6.5 h1:M5dcIe1zQYvGpY2K07UNkNU9Obc4U+A1fz68Ho/Q+XE=
github.com/ethersphere/go-sw3-abi v0.6.5/go.mod h1:BmpsvJ8idQZdYEtWnvxA8POYQ8Rl/NhyCdF0zLMOOJU=
github.com/ethersphere/langos v1.0.0 h1:NBtNKzXTTRSue95uOlzPN4py7Aofs0xWPzyj4AI1Vcc=
Expand Down
6 changes: 3 additions & 3 deletions pkg/storageincentives/redistribution/redistribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (c *contract) Claim(ctx context.Context, proofs ChunkInclusionProofs) (comm

// 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) {
callData, err := c.incentivesContractABI.Pack("commit", common.BytesToHash(obfusHash), common.BytesToHash(c.overlay.Bytes()), round)
callData, err := c.incentivesContractABI.Pack("commit", common.BytesToHash(obfusHash), round)
if err != nil {
return common.Hash{}, err
}
Expand All @@ -131,15 +131,15 @@ func (c *contract) Commit(ctx context.Context, obfusHash []byte, round uint64) (
}
txHash, err := c.sendAndWait(ctx, request, 50)
if err != nil {
return txHash, fmt.Errorf("commit: obfusHash %v overlay %v: %w", common.BytesToHash(obfusHash), common.BytesToHash(c.overlay.Bytes()), err)
return txHash, fmt.Errorf("commit: obfusHash %v: %w", common.BytesToHash(obfusHash), err)
}

return txHash, nil
}

// Reveal submits the storageDepth, reserveCommitmentHash and RandomNonce in a transaction to blockchain.
func (c *contract) Reveal(ctx context.Context, storageDepth uint8, reserveCommitmentHash []byte, RandomNonce []byte) (common.Hash, error) {
callData, err := c.incentivesContractABI.Pack("reveal", common.BytesToHash(c.overlay.Bytes()), storageDepth, common.BytesToHash(reserveCommitmentHash), common.BytesToHash(RandomNonce))
callData, err := c.incentivesContractABI.Pack("reveal", storageDepth, common.BytesToHash(reserveCommitmentHash), common.BytesToHash(RandomNonce))
if err != nil {
return common.Hash{}, err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/storageincentives/redistribution/redistribution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,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, uint64(0))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -310,7 +310,7 @@ func TestRedistribution(t *testing.T) {
randomNonce := common.BytesToHash(common.Hex2Bytes("nonce"))
depth := uint8(10)

expectedCallData, err := redistributionContractABI.Pack("reveal", common.BytesToHash(owner.Bytes()), depth, reserveCommitmentHash, randomNonce)
expectedCallData, err := redistributionContractABI.Pack("reveal", depth, reserveCommitmentHash, randomNonce)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -402,7 +402,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")), uint64(0))
if err != nil {
t.Fatal(err)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/storageincentives/staking/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (c *contract) sendTransaction(ctx context.Context, callData []byte, desc st
}

func (c *contract) sendDepositStakeTransaction(ctx context.Context, owner common.Address, stakedAmount *big.Int, nonce common.Hash) (*types.Receipt, error) {
callData, err := c.stakingContractABI.Pack("depositStake", owner, nonce, stakedAmount)
callData, err := c.stakingContractABI.Pack("manageStake", nonce, stakedAmount)
if err != nil {
return nil, err
}
Expand All @@ -171,7 +171,7 @@ func (c *contract) sendDepositStakeTransaction(ctx context.Context, owner common
func (c *contract) getStake(ctx context.Context, overlay swarm.Address) (*big.Int, error) {
var overlayAddr [32]byte
copy(overlayAddr[:], overlay.Bytes())
callData, err := c.stakingContractABI.Pack("stakeOfOverlay", overlayAddr)
callData, err := c.stakingContractABI.Pack("stakeOfAddress", overlayAddr)
if err != nil {
return nil, err
}
Expand All @@ -183,7 +183,7 @@ func (c *contract) getStake(ctx context.Context, overlay swarm.Address) (*big.In
return nil, fmt.Errorf("get stake: overlayAddress %d: %w", overlay, err)
}

results, err := c.stakingContractABI.Unpack("stakeOfOverlay", result)
results, err := c.stakingContractABI.Unpack("stakeOfAddress", result)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -300,7 +300,7 @@ func (c *contract) withdrawFromStake(ctx context.Context, stakedAmount *big.Int)
var overlayAddr [32]byte
copy(overlayAddr[:], c.overlay.Bytes())

callData, err := c.stakingContractABI.Pack("withdrawFromStake", overlayAddr, stakedAmount)
callData, err := c.stakingContractABI.Pack("withdrawFromStake", stakedAmount)
if err != nil {
return nil, err
}
Expand Down
38 changes: 19 additions & 19 deletions pkg/storageincentives/staking/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestDepositStake(t *testing.T) {

totalAmount := big.NewInt(100000000000000000)
prevStake := big.NewInt(0)
expectedCallData, err := stakingContractABI.Pack("depositStake", common.BytesToHash(owner.Bytes()), nonce, stakedAmount)
expectedCallData, err := stakingContractABI.Pack("manageStake", nonce, stakedAmount)
if err != nil {
t.Fatal(err)
}
Expand All @@ -59,7 +59,7 @@ func TestDepositStake(t *testing.T) {
return txHashApprove, nil
}
if *request.To == stakingContractAddress {
if !bytes.Equal(expectedCallData[:100], request.Data[:100]) {
if !bytes.Equal(expectedCallData[:80], request.Data[:80]) {
return common.Hash{}, fmt.Errorf("got wrong call data. wanted %x, got %x", expectedCallData, request.Data)
}
return txHashDeposited, nil
Expand Down Expand Up @@ -103,7 +103,7 @@ func TestDepositStake(t *testing.T) {

totalAmount := big.NewInt(100000000000000000)
prevStake := big.NewInt(2)
expectedCallData, err := stakingContractABI.Pack("depositStake", common.BytesToHash(owner.Bytes()), nonce, big.NewInt(100000000000000000))
expectedCallData, err := stakingContractABI.Pack("manageStake", nonce, big.NewInt(100000000000000000))
if err != nil {
t.Fatal(err)
}
Expand All @@ -120,7 +120,7 @@ func TestDepositStake(t *testing.T) {
return txHashApprove, nil
}
if *request.To == stakingContractAddress {
if !bytes.Equal(expectedCallData[:100], request.Data[:100]) {
if !bytes.Equal(expectedCallData[:80], request.Data[:80]) {
return common.Hash{}, fmt.Errorf("got wrong call data. wanted %x, got %x", expectedCallData, request.Data)
}
return txHashDeposited, nil
Expand Down Expand Up @@ -371,7 +371,7 @@ func TestDepositStake(t *testing.T) {
return txHashApprove, nil
}
if *request.To == stakingContractAddress {
if !bytes.Equal(expectedCallData[:100], request.Data[:100]) {
if !bytes.Equal(expectedCallData[:80], request.Data[:80]) {
return common.Hash{}, fmt.Errorf("got wrong call data. wanted %x, got %x", expectedCallData, request.Data)
}
return txHashDeposited, nil
Expand Down Expand Up @@ -432,7 +432,7 @@ func TestDepositStake(t *testing.T) {
return txHashApprove, nil
}
if *request.To == stakingContractAddress {
if !bytes.Equal(expectedCallData[:100], request.Data[:100]) {
if !bytes.Equal(expectedCallData[:80], request.Data[:80]) {
return common.Hash{}, fmt.Errorf("got wrong call data. wanted %x, got %x", expectedCallData, request.Data)
}
return txHashDeposited, nil
Expand Down Expand Up @@ -510,7 +510,7 @@ func TestGetStake(t *testing.T) {
t.Parallel()

prevStake := big.NewInt(0)
expectedCallData, err := stakingContractABI.Pack("stakeOfOverlay", common.BytesToHash(addr.Bytes()))
expectedCallData, err := stakingContractABI.Pack("stakeOfAddress", common.BytesToHash(addr.Bytes()))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -546,7 +546,7 @@ func TestGetStake(t *testing.T) {

t.Run("error with unpacking", func(t *testing.T) {
t.Parallel()
expectedCallData, err := stakingContractABI.Pack("stakeOfOverlay", common.BytesToHash(addr.Bytes()))
expectedCallData, err := stakingContractABI.Pack("stakeOfAddress", common.BytesToHash(addr.Bytes()))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -581,7 +581,7 @@ func TestGetStake(t *testing.T) {
t.Parallel()

prevStake := big.NewInt(0)
expectedCallData, err := stakingContractABI.Pack("stakeOfOverlay", common.BytesToHash(owner.Bytes()))
expectedCallData, err := stakingContractABI.Pack("stakeOfAddress", common.BytesToHash(owner.Bytes()))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -658,12 +658,12 @@ func TestWithdrawStake(t *testing.T) {
t.Fatal(err)
}

expectedCallDataForWithdraw, err := stakingContractABI.Pack("withdrawFromStake", common.BytesToHash(addr.Bytes()), stakedAmount)
expectedCallDataForWithdraw, err := stakingContractABI.Pack("withdrawFromStake", stakedAmount)
if err != nil {
t.Fatal(err)
}

expectedCallDataForGetStake, err := stakingContractABI.Pack("stakeOfOverlay", common.BytesToHash(addr.Bytes()))
expectedCallDataForGetStake, err := stakingContractABI.Pack("stakeOfAddress", common.BytesToHash(addr.Bytes()))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -766,7 +766,7 @@ func TestWithdrawStake(t *testing.T) {

invalidStakedAmount := big.NewInt(0)

expectedCallDataForGetStake, err := stakingContractABI.Pack("stakeOfOverlay", common.BytesToHash(addr.Bytes()))
expectedCallDataForGetStake, err := stakingContractABI.Pack("stakeOfAddress", common.BytesToHash(addr.Bytes()))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -805,12 +805,12 @@ func TestWithdrawStake(t *testing.T) {
if err == nil {
t.Fatal(err)
}
_, err = stakingContractABI.Pack("withdrawFromStake", stakedAmount)
_, err = stakingContractABI.Pack("withdrawFromStake", common.BytesToHash(addr.Bytes()), stakedAmount)
if err == nil {
t.Fatal(err)
}

_, err = stakingContractABI.Pack("stakeOfOverlay", stakedAmount)
_, err = stakingContractABI.Pack("stakeOfAddress", stakedAmount)
if err == nil {
t.Fatal(err)
}
Expand All @@ -826,12 +826,12 @@ func TestWithdrawStake(t *testing.T) {
t.Fatal(err)
}

expectedCallDataForWithdraw, err := stakingContractABI.Pack("withdrawFromStake", common.BytesToHash(addr.Bytes()), stakedAmount)
expectedCallDataForWithdraw, err := stakingContractABI.Pack("withdrawFromStake", stakedAmount)
if err != nil {
t.Fatal(err)
}

expectedCallDataForGetStake, err := stakingContractABI.Pack("stakeOfOverlay", common.BytesToHash(addr.Bytes()))
expectedCallDataForGetStake, err := stakingContractABI.Pack("stakeOfAddress", common.BytesToHash(addr.Bytes()))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -899,12 +899,12 @@ func TestWithdrawStake(t *testing.T) {
t.Fatal(err)
}

expectedCallDataForGetStake, err := stakingContractABI.Pack("stakeOfOverlay", common.BytesToHash(addr.Bytes()))
expectedCallDataForGetStake, err := stakingContractABI.Pack("stakeOfAddress", common.BytesToHash(addr.Bytes()))
if err != nil {
t.Fatal(err)
}

expectedCallDataForWithdraw, err := stakingContractABI.Pack("withdrawFromStake", common.BytesToHash(addr.Bytes()), stakedAmount)
expectedCallDataForWithdraw, err := stakingContractABI.Pack("withdrawFromStake", stakedAmount)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1003,7 +1003,7 @@ func TestWithdrawStake(t *testing.T) {
t.Fatal(err)
}

expectedCallDataForGetStake, err := stakingContractABI.Pack("stakeOfOverlay", common.BytesToHash(addr.Bytes()))
expectedCallDataForGetStake, err := stakingContractABI.Pack("stakeOfAddress", common.BytesToHash(addr.Bytes()))
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit d2d3744

Please sign in to comment.