Skip to content

Commit

Permalink
Revert "test: fix e2e tests (#197)"
Browse files Browse the repository at this point in the history
This reverts commit d732eeb.
  • Loading branch information
jacobhjkim authored Aug 13, 2024
1 parent d732eeb commit 60805ba
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 65 deletions.
1 change: 0 additions & 1 deletion config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ 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.1-0.20240613200951-b074924938f8
github.com/stretchr/testify v1.9.0
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.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/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/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: 9 additions & 11 deletions tests/e2e/e2e_bank_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package e2e

import (
"crypto/rand"
"time"

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

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

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 @@ -48,9 +52,3 @@ func (s *IntegrationTestSuite) TestBankTokenTransfer() {
)
})
}

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

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

Expand Down
76 changes: 34 additions & 42 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(faucetAddr, s.admin, initialAmount, standardFees.String())
s.execBankSend(treasuryAddr, 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)
require.NoError(c, err)
require.Equal(c, len(beforeTenants)+1, len(afterTenants))
s.Require().NoError(err)
s.Require().Equal(len(beforeTenants)+1, len(afterTenants))

newTenant := afterTenants[len(afterTenants)-1]
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)
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)

tenantId = newTenant.Tenant.Id
tenantContractAddr = newTenant.Tenant.ContractAddress
Expand All @@ -211,37 +211,29 @@ 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)

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_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_external_nft_revenue", func() {
beforeBalance, err := queryERC20Balance(s.ethClient, tenantContractAddr, extNftOwner)
Expand All @@ -253,11 +245,11 @@ func (s *IntegrationTestSuite) TestMintableContractTenant() {
s.Require().EventuallyWithT(
func(c *assert.CollectT) {
utxr, err := queryUtxr(chainAPIEndpoint, tenantId, requestId)
require.NoError(c, err)
require.Equal(c, revenue, utxr.Amount)
s.Require().NoError(err)
s.Require().Equal(revenue, utxr.Amount)

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

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

type IntegrationTestSuite struct {
Expand Down
6 changes: 1 addition & 5 deletions 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, fmt.Errorf("failed to unmarshal JSON: %w, %v", err, body)
return nil, err
}

return &utxrResp.Utxr, nil
Expand All @@ -104,10 +104,6 @@ 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

0 comments on commit 60805ba

Please sign in to comment.