Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
permissions: Disable integration test
Browse files Browse the repository at this point in the history
cdamian committed Dec 12, 2023
1 parent a521665 commit e6aff3b
Showing 1 changed file with 87 additions and 93 deletions.
180 changes: 87 additions & 93 deletions pallets/permissions/api_integration_test.go
Original file line number Diff line number Diff line change
@@ -3,14 +3,9 @@
package permissions_test

import (
"context"
"math/big"
"math/rand"
"os"
"testing"
"time"

"github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/centrifuge/pod/bootstrap"
"github.com/centrifuge/pod/bootstrap/bootstrappers/integration_test"
"github.com/centrifuge/pod/bootstrap/bootstrappers/testlogging"
@@ -22,11 +17,8 @@ import (
"github.com/centrifuge/pod/jobs"
"github.com/centrifuge/pod/pallets"
"github.com/centrifuge/pod/pallets/permissions"
"github.com/centrifuge/pod/pallets/utility"
"github.com/centrifuge/pod/storage/leveldb"
genericUtils "github.com/centrifuge/pod/testingutils/generic"
"github.com/centrifuge/pod/testingutils/keyrings"
"github.com/stretchr/testify/assert"
)

var integrationTestBootstrappers = []bootstrap.TestBootstrapper{
@@ -60,88 +52,90 @@ func TestMain(m *testing.M) {
os.Exit(result)
}

func TestIntegration_PermissionRolesRetrieval(t *testing.T) {
testKeyring := keyrings.AliceKeyRingPair

testAccountID, err := types.NewAccountID(testKeyring.PublicKey)
assert.NoError(t, err)

poolID := types.U64(rand.Uint32())

// Create a pool using Alice's account as the owner.

registerPoolCall := pallets.GetRegisterPoolCallCreationFn(
testAccountID,
poolID,
[]pallets.TrancheInput{
{
TrancheType: pallets.TrancheType{
IsResidual: true,
},
Seniority: types.NewOption[types.U32](0),
TrancheMetadata: pallets.TrancheMetadata{
TokenName: []byte("CFG-TEST-1"),
TokenSymbol: []byte("CFGT1"),
},
},
{
TrancheType: pallets.TrancheType{
IsNonResidual: true,
AsNonResidual: pallets.NonResidual{
InterestRatePerSec: types.NewU128(*big.NewInt(1)),
MinRiskBuffer: 5,
},
},
Seniority: types.NewOption[types.U32](1),
TrancheMetadata: pallets.TrancheMetadata{
TokenName: []byte("CFG-TEST-2"),
TokenSymbol: []byte("CFGT2"),
},
},
},
pallets.CurrencyID{
IsForeignAsset: true,
AsForeignAsset: types.U32(1),
},
types.NewU128(*big.NewInt(rand.Int63())),
[]byte("test"),
)

// Assign the Borrower permission to Alice's account.

addBorrowerPermissionsCall := pallets.GetPermissionsCallCreationFn(
pallets.Role{
IsPoolRole: true,
AsPoolRole: pallets.PoolRole{IsPoolAdmin: true},
},
testAccountID,
pallets.PermissionScope{
IsPool: true,
AsPool: poolID,
},
pallets.Role{
IsPoolRole: true,
AsPoolRole: pallets.PoolRole{IsBorrower: true},
},
)

// Execute the batch call using the test keyring.

ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
defer cancel()

err = pallets.ExecuteWithTestClient(
ctx,
serviceCtx,
testKeyring,
utility.BatchCalls(
registerPoolCall,
addBorrowerPermissionsCall,
),
)
assert.NoError(t, err)

res, err := permissionsAPI.GetPermissionRoles(testAccountID, poolID)
assert.NoError(t, err)
assert.True(t, res.PoolAdmin&permissions.Borrower == permissions.Borrower)
}
// NOTE - The following test is disabled for now since we have to update the pool-related entities.
//
//func TestIntegration_PermissionRolesRetrieval(t *testing.T) {
// testKeyring := keyrings.AliceKeyRingPair
//
// testAccountID, err := types.NewAccountID(testKeyring.PublicKey)
// assert.NoError(t, err)
//
// poolID := types.U64(rand.Uint32())
//
// // Create a pool using Alice's account as the owner.
//
// registerPoolCall := pallets.GetRegisterPoolCallCreationFn(
// testAccountID,
// poolID,
// []pallets.TrancheInput{
// {
// TrancheType: pallets.TrancheType{
// IsResidual: true,
// },
// Seniority: types.NewOption[types.U32](0),
// TrancheMetadata: pallets.TrancheMetadata{
// TokenName: []byte("CFG-TEST-1"),
// TokenSymbol: []byte("CFGT1"),
// },
// },
// {
// TrancheType: pallets.TrancheType{
// IsNonResidual: true,
// AsNonResidual: pallets.NonResidual{
// InterestRatePerSec: types.NewU128(*big.NewInt(1)),
// MinRiskBuffer: 5,
// },
// },
// Seniority: types.NewOption[types.U32](1),
// TrancheMetadata: pallets.TrancheMetadata{
// TokenName: []byte("CFG-TEST-2"),
// TokenSymbol: []byte("CFGT2"),
// },
// },
// },
// pallets.CurrencyID{
// IsForeignAsset: true,
// AsForeignAsset: types.U32(1),
// },
// types.NewU128(*big.NewInt(rand.Int63())),
// []byte("test"),
// )
//
// // Assign the Borrower permission to Alice's account.
//
// addBorrowerPermissionsCall := pallets.GetPermissionsCallCreationFn(
// pallets.Role{
// IsPoolRole: true,
// AsPoolRole: pallets.PoolRole{IsPoolAdmin: true},
// },
// testAccountID,
// pallets.PermissionScope{
// IsPool: true,
// AsPool: poolID,
// },
// pallets.Role{
// IsPoolRole: true,
// AsPoolRole: pallets.PoolRole{IsBorrower: true},
// },
// )
//
// // Execute the batch call using the test keyring.
//
// ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
// defer cancel()
//
// err = pallets.ExecuteWithTestClient(
// ctx,
// serviceCtx,
// testKeyring,
// utility.BatchCalls(
// registerPoolCall,
// addBorrowerPermissionsCall,
// ),
// )
// assert.NoError(t, err)
//
// res, err := permissionsAPI.GetPermissionRoles(testAccountID, poolID)
// assert.NoError(t, err)
// assert.True(t, res.PoolAdmin&permissions.Borrower == permissions.Borrower)
//}

0 comments on commit e6aff3b

Please sign in to comment.