Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix e2e tests #197

Merged
merged 4 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ accounts:
- name: faucet
coins:
- 10000000000000000000000000asetl
- 10000000000000000000000000uusdc
mnemonic: island club point history solution tonight festival maid zebra business nasty clap spirit science excess win caution hand embrace heavy snow derive nuclear head
client:
typescript:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ require (
github.com/spf13/cast v1.6.0
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.9.0
github.com/stretchr/testify v1.9.1-0.20240613200951-b074924938f8
go.opencensus.io v0.24.0
google.golang.org/genproto/googleapis/api v0.0.0-20240723171418-e6d459c13d2a
google.golang.org/grpc v1.65.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1278,8 +1278,8 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.9.1-0.20240613200951-b074924938f8 h1:lMSOB3NNaQcNDK9eCjQb0LFfpXW03lzF2SN6vUziALo=
github.com/stretchr/testify v1.9.1-0.20240613200951-b074924938f8/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/supranational/blst v0.3.8-0.20220526154634-513d2456b344/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw=
Expand Down
20 changes: 11 additions & 9 deletions tests/e2e/e2e_bank_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package e2e

import (
"crypto/rand"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -9,22 +10,17 @@ import (
func (s *IntegrationTestSuite) TestBankTokenTransfer() {
s.Run("send_setl_between_accounts", func() {
var err error
sender := treasuryAddr
recipient := "settlus10z74aw2m660tuezej4w5zr35zye6684t5ejjmk"
sender := bobAddr
recipient := makeRandomAccAddress()

var (
beforeSenderASetlBalance sdk.Coin
beforeRecipientASetlBalance sdk.Coin
)
var beforeSenderASetlBalance sdk.Coin
beforeRecipientASetlBalance := sdk.NewCoin(asetlDenom, sdk.NewInt(0))

s.Require().Eventually(
func() bool {
beforeSenderASetlBalance, err = getSpecificBalance(chainAPIEndpoint, sender, asetlDenom)
s.Require().NoError(err)

beforeRecipientASetlBalance, err = getSpecificBalance(chainAPIEndpoint, recipient, asetlDenom)
s.Require().NoError(err)

return true
},
10*time.Second,
Expand Down Expand Up @@ -52,3 +48,9 @@ func (s *IntegrationTestSuite) TestBankTokenTransfer() {
)
})
}

func makeRandomAccAddress() string {
recipientBytes := make([]byte, 20)
_, _ = rand.Read(recipientBytes)
return sdk.AccAddress(recipientBytes).String()
}
1 change: 0 additions & 1 deletion tests/e2e/e2e_exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ func (s *IntegrationTestSuite) execRecord(
settlusCmd = append(settlusCmd, fmt.Sprintf("--%s=%v", flag, value))
}

fmt.Println(settlusCmd)
s.executeSettlusTxCommand(ctx, settlusCmd)
}

Expand Down
76 changes: 42 additions & 34 deletions tests/e2e/e2e_settlement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (s *IntegrationTestSuite) SetupSettlementTestSuite() {
admin := "admin" + strconv.Itoa(rand.Intn(10000000000))
s.admin = s.execKeyAdd(admin)
initialAmount := fmt.Sprintf("%d%s,%d%s", 10000000000000, asetlDenom, 10000000000000, uusdcDenom)
s.execBankSend(treasuryAddr, s.admin, initialAmount, standardFees.String())
s.execBankSend(faucetAddr, s.admin, initialAmount, standardFees.String())
s.Require().EventuallyWithT(
func(c *assert.CollectT) {
balance, err := getSpecificBalance(chainAPIEndpoint, s.admin, asetlDenom)
Expand Down Expand Up @@ -192,14 +192,14 @@ func (s *IntegrationTestSuite) TestMintableContractTenant() {
s.Require().EventuallyWithT(
func(c *assert.CollectT) {
afterTenants, err := queryTenants(chainAPIEndpoint)
s.Require().NoError(err)
s.Require().Equal(len(beforeTenants)+1, len(afterTenants))
require.NoError(c, err)
require.Equal(c, len(beforeTenants)+1, len(afterTenants))

newTenant := afterTenants[len(afterTenants)-1]
s.Require().Equal(denom, newTenant.Tenant.Denom)
s.Require().Equal(period, int(newTenant.Tenant.PayoutPeriod))
s.Require().Equal(types.PayoutMethod_MintContract, newTenant.Tenant.PayoutMethod)
s.Require().NotEmpty(newTenant.Tenant.ContractAddress)
require.Equal(c, denom, newTenant.Tenant.Denom)
require.Equal(c, period, int(newTenant.Tenant.PayoutPeriod))
require.Equal(c, types.PayoutMethod_MintContract, newTenant.Tenant.PayoutMethod)
require.NotEmpty(c, newTenant.Tenant.ContractAddress)

tenantId = newTenant.Tenant.Id
tenantContractAddr = newTenant.Tenant.ContractAddress
Expand All @@ -211,29 +211,37 @@ func (s *IntegrationTestSuite) TestMintableContractTenant() {
})
s.Require().True(pass)

//pass = s.Run("record_internal_nft_revenue", func() {
// requestId := NewReqId()
// s.execRecord(s.admin, tenantId, requestId, revenue.String(), chainId, s.internalNftAddr, internalNftId)
//
// utxr, err := queryUtxr(chainAPIEndpoint, tenantId, requestId)
// s.Require().NoError(err)
// s.Require().Equal(common.FromHex(internalNftOwner), utxr.Recipients[0].Address.Bytes())
// s.Require().Equal(revenue, utxr.Amount)
//
// beforeBalance, err := queryERC20Balance(s.ethClient, tenantContractAddr, internalNftOwner)
// s.Require().NoError(err)
//
// s.Require().Eventually(
// func() bool {
// afterBalance, err := queryERC20Balance(s.ethClient, tenantContractAddr, internalNftOwner)
// s.Require().NoError(err)
// return afterBalance-beforeBalance == revenue.Amount.Uint64()
// },
// time.Minute,
// 2*time.Second,
// )
//})
//s.Require().True(pass)
pass = s.Run("record_internal_nft_revenue", func() {
requestId := NewReqId()
s.execRecord(s.admin, tenantId, requestId, revenue.String(), chainId, s.internalNftAddr, internalNftId)

s.Require().EventuallyWithT(
func(c *assert.CollectT) {
utxr, err := queryUtxr(chainAPIEndpoint, tenantId, requestId)
require.NoError(c, err)
require.Equal(c, 1, len(utxr.Recipients))
require.Equal(c, common.FromHex(internalNftOwner), utxr.Recipients[0].Address.Bytes())
require.Equal(c, revenue, utxr.Amount)
},
10*time.Second,
time.Second,
"failed to query UTXR after recording internal NFT revenue",
)

beforeBalance, err := queryERC20Balance(s.ethClient, tenantContractAddr, internalNftOwner)
s.Require().NoError(err)

s.Require().Eventually(
func() bool {
afterBalance, err := queryERC20Balance(s.ethClient, tenantContractAddr, internalNftOwner)
s.Require().NoError(err)
return afterBalance-beforeBalance == revenue.Amount.Uint64()
},
time.Minute,
2*time.Second,
)
})
s.Require().True(pass)

pass = s.Run("record_external_nft_revenue", func() {
beforeBalance, err := queryERC20Balance(s.ethClient, tenantContractAddr, extNftOwner)
Expand All @@ -245,11 +253,11 @@ func (s *IntegrationTestSuite) TestMintableContractTenant() {
s.Require().EventuallyWithT(
func(c *assert.CollectT) {
utxr, err := queryUtxr(chainAPIEndpoint, tenantId, requestId)
s.Require().NoError(err)
s.Require().Equal(revenue, utxr.Amount)
require.NoError(c, err)
require.Equal(c, revenue, utxr.Amount)

s.Require().Greater(len(utxr.Recipients), 0)
s.Require().Equal(common.FromHex(extNftOwner), utxr.Recipients[0].Address.Bytes())
require.Greater(c, len(utxr.Recipients), 0)
require.Equal(c, common.FromHex(extNftOwner), utxr.Recipients[0].Address.Bytes())
},
time.Minute,
time.Second,
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/e2e_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const (

var (
standardFees = sdk.NewCoin(asetlDenom, sdk.NewInt(300000000000000))
treasuryAddr = "settlus12g8w5dr5jyncct8jwdxwsy2g9ktdrjjlcs5f0a"
faucetAddr = "settlus10z74aw2m660tuezej4w5zr35zye6684t5ejjmk" // faucet address specified in the config.yml
bobAddr = "settlus1vfhltz7wr4ca862xd0azjuap4tupwgyzk7qukp" // bob address specified in the config.yml
)

type IntegrationTestSuite struct {
Expand Down
6 changes: 5 additions & 1 deletion tests/e2e/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func queryUtxr(endpoint string, tenantId uint64, requestId string) (*settlementt

var utxrResp settlementtypes.QueryUTXRResponse
if err := cdc.UnmarshalJSON(body, &utxrResp); err != nil {
return nil, err
return nil, fmt.Errorf("failed to unmarshal JSON: %w, %v", err, body)
}

return &utxrResp.Utxr, nil
Expand All @@ -104,6 +104,10 @@ func querySettlusAllBalances(endpoint, addr string) (sdk.Coins, error) {
return nil, err
}

if balancesResp.Balances == nil || len(balancesResp.Balances) == 0 {
return nil, fmt.Errorf("balances are nil or empty for address %s", addr)
}

return balancesResp.Balances, nil
}

Expand Down
2 changes: 1 addition & 1 deletion types/nft.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package types

import (
fmt "fmt"
"fmt"
"strings"
)

Expand Down
Loading