Skip to content

Commit

Permalink
add E2E test for token plugins with remote names
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Shorsher <alex.shorsher@kaleido.io>
  • Loading branch information
shorsher committed Aug 3, 2022
1 parent 4ac033b commit 6577b38
Show file tree
Hide file tree
Showing 2 changed files with 195 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/e2e/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,10 @@ func RandomName(t *testing.T) string {
assert.NoError(t, err)
return fmt.Sprintf("e2e_%x", b)
}

func AddPluginRemoteName(data map[string]interface{}, pluginType, remoteName string) {
pluginsConfig := data["plugins"].(map[interface{}]interface{})
plugins := pluginsConfig[pluginType].([]interface{})
plugin := plugins[0].(map[interface{}]interface{})
plugin["remoteName"] = remoteName
}
188 changes: 188 additions & 0 deletions test/e2e/multiparty/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,191 @@ func (suite *TokensTestSuite) TestE2ENonFungibleTokensSync() {
accountPools = suite.testState.client2.GetTokenAccountPools(suite.T(), suite.testState.org2key.Value)
assert.Equal(suite.T(), *poolID, *accountPools[0].Pool)
}

func (suite *TokensTestSuite) TestE2EFungibleTokensWithRemoteNameAsync() {
defer suite.testState.done()
config1 := e2e.ReadConfig(suite.T(), suite.testState.configFile1)
e2e.AddPluginRemoteName(config1, "tokens", "testremote")
e2e.WriteConfig(suite.T(), suite.testState.configFile1, config1)

config2 := e2e.ReadConfig(suite.T(), suite.testState.configFile2)
e2e.AddPluginRemoteName(config2, "tokens", "testremote")
e2e.WriteConfig(suite.T(), suite.testState.configFile2, config2)

admin1 := client.NewResty(suite.T())
admin2 := client.NewResty(suite.T())
admin1.SetBaseURL(suite.testState.adminHost1 + "/spi/v1")
admin2.SetBaseURL(suite.testState.adminHost2 + "/spi/v1")

e2e.ResetFireFly(suite.T(), admin1)
e2e.ResetFireFly(suite.T(), admin2)
e2e.PollForUp(suite.T(), suite.testState.client1)
e2e.PollForUp(suite.T(), suite.testState.client2)

client1 := client.NewFireFly(suite.T(), suite.testState.client1.Hostname, suite.testState.namespace)
client2 := client.NewFireFly(suite.T(), suite.testState.client2.Hostname, suite.testState.namespace)

eventNames := "message_confirmed|token_pool_confirmed|token_transfer_confirmed|token_approval_confirmed"
queryString := fmt.Sprintf("namespace=%s&ephemeral&autoack&filter.events=%s", suite.testState.namespace, eventNames)
received1 := e2e.WsReader(client1.WebSocket(suite.T(), queryString, nil))
received2 := e2e.WsReader(client2.WebSocket(suite.T(), queryString, nil))

poolName := fmt.Sprintf("pool_%s", e2e.RandomName(suite.T()))
suite.T().Logf("Pool name: %s", poolName)

pool := &core.TokenPool{
Name: poolName,
Type: core.TokenTypeFungible,
Config: fftypes.JSONObject{},
}

poolResp := client1.CreateTokenPool(suite.T(), pool, false)
poolID := poolResp.ID

e2e.WaitForEvent(suite.T(), received1, core.EventTypePoolConfirmed, poolID)
pools := client1.GetTokenPools(suite.T(), suite.testState.startTime)
assert.Equal(suite.T(), 1, len(pools))
assert.Equal(suite.T(), suite.testState.namespace, pools[0].Namespace)
assert.Equal(suite.T(), suite.connector, pools[0].Connector)
assert.Equal(suite.T(), poolName, pools[0].Name)
assert.Equal(suite.T(), core.TokenTypeFungible, pools[0].Type)
assert.NotEmpty(suite.T(), pools[0].Locator)

e2e.WaitForEvent(suite.T(), received2, core.EventTypePoolConfirmed, poolID)
pools = client1.GetTokenPools(suite.T(), suite.testState.startTime)
assert.Equal(suite.T(), 1, len(pools))
assert.Equal(suite.T(), suite.testState.namespace, pools[0].Namespace)
assert.Equal(suite.T(), suite.connector, pools[0].Connector)
assert.Equal(suite.T(), poolName, pools[0].Name)
assert.Equal(suite.T(), core.TokenTypeFungible, pools[0].Type)
assert.NotEmpty(suite.T(), pools[0].Locator)

approval := &core.TokenApprovalInput{
TokenApproval: core.TokenApproval{
Key: suite.testState.org1key.Value,
Operator: suite.testState.org2key.Value,
Approved: true,
},
Pool: poolName,
}
approvalOut := client1.TokenApproval(suite.T(), approval, false)

e2e.WaitForEvent(suite.T(), received1, core.EventTypeApprovalConfirmed, approvalOut.LocalID)
approvals := client1.GetTokenApprovals(suite.T(), poolID)
assert.Equal(suite.T(), 1, len(approvals))
assert.Equal(suite.T(), suite.connector, approvals[0].Connector)
assert.Equal(suite.T(), true, approvals[0].Approved)

transfer := &core.TokenTransferInput{
TokenTransfer: core.TokenTransfer{Amount: *fftypes.NewFFBigInt(1)},
Pool: poolName,
}
transferOut := client1.MintTokens(suite.T(), transfer, false)

e2e.WaitForEvent(suite.T(), received1, core.EventTypeTransferConfirmed, transferOut.LocalID)
transfers := client1.GetTokenTransfers(suite.T(), poolID)
assert.Equal(suite.T(), 1, len(transfers))
assert.Equal(suite.T(), suite.connector, transfers[0].Connector)
assert.Equal(suite.T(), core.TokenTransferTypeMint, transfers[0].Type)
assert.Equal(suite.T(), int64(1), transfers[0].Amount.Int().Int64())
e2e.ValidateAccountBalances(suite.T(), client1, poolID, "", map[string]int64{
suite.testState.org1key.Value: 1,
})

e2e.WaitForEvent(suite.T(), received2, core.EventTypeTransferConfirmed, nil)
transfers = client2.GetTokenTransfers(suite.T(), poolID)
assert.Equal(suite.T(), 1, len(transfers))
assert.Equal(suite.T(), suite.connector, transfers[0].Connector)
assert.Equal(suite.T(), core.TokenTransferTypeMint, transfers[0].Type)
assert.Equal(suite.T(), int64(1), transfers[0].Amount.Int().Int64())
e2e.ValidateAccountBalances(suite.T(), client2, poolID, "", map[string]int64{
suite.testState.org1key.Value: 1,
})

transfer = &core.TokenTransferInput{
TokenTransfer: core.TokenTransfer{
To: suite.testState.org2key.Value,
Amount: *fftypes.NewFFBigInt(1),
From: suite.testState.org1key.Value,
Key: suite.testState.org2key.Value,
},
Pool: poolName,
Message: &core.MessageInOut{
InlineData: core.InlineData{
{
Value: fftypes.JSONAnyPtr(`"token approval - payment for data"`),
},
},
},
}
transferOut = client2.TransferTokens(suite.T(), transfer, false)

e2e.WaitForEvent(suite.T(), received1, core.EventTypeMessageConfirmed, transferOut.Message)
transfers = client1.GetTokenTransfers(suite.T(), poolID)
assert.Equal(suite.T(), 2, len(transfers))
assert.Equal(suite.T(), suite.connector, transfers[0].Connector)
assert.Equal(suite.T(), core.TokenTransferTypeTransfer, transfers[0].Type)
assert.Equal(suite.T(), int64(1), transfers[0].Amount.Int().Int64())
data := client1.GetDataForMessage(suite.T(), suite.testState.startTime, transfers[0].Message)
assert.Equal(suite.T(), 1, len(data))
assert.Equal(suite.T(), `"token approval - payment for data"`, data[0].Value.String())
e2e.ValidateAccountBalances(suite.T(), client1, poolID, "", map[string]int64{
suite.testState.org1key.Value: 0,
suite.testState.org2key.Value: 1,
})

e2e.WaitForEvent(suite.T(), received2, core.EventTypeMessageConfirmed, transferOut.Message)
transfers = client2.GetTokenTransfers(suite.T(), poolID)
assert.Equal(suite.T(), 2, len(transfers))
assert.Equal(suite.T(), suite.connector, transfers[0].Connector)
assert.Equal(suite.T(), core.TokenTransferTypeTransfer, transfers[0].Type)
assert.Equal(suite.T(), int64(1), transfers[0].Amount.Int().Int64())
e2e.ValidateAccountBalances(suite.T(), client2, poolID, "", map[string]int64{
suite.testState.org1key.Value: 0,
suite.testState.org2key.Value: 1,
})

transfer = &core.TokenTransferInput{
TokenTransfer: core.TokenTransfer{Amount: *fftypes.NewFFBigInt(1)},
Pool: poolName,
}
transferOut = client2.BurnTokens(suite.T(), transfer, false)

e2e.WaitForEvent(suite.T(), received2, core.EventTypeTransferConfirmed, transferOut.LocalID)
transfers = client2.GetTokenTransfers(suite.T(), poolID)
assert.Equal(suite.T(), 3, len(transfers))
assert.Equal(suite.T(), suite.connector, transfers[0].Connector)
assert.Equal(suite.T(), core.TokenTransferTypeBurn, transfers[0].Type)
assert.Equal(suite.T(), "", transfers[0].TokenIndex)
assert.Equal(suite.T(), int64(1), transfers[0].Amount.Int().Int64())
e2e.ValidateAccountBalances(suite.T(), client2, poolID, "", map[string]int64{
suite.testState.org1key.Value: 0,
suite.testState.org2key.Value: 0,
})

e2e.WaitForEvent(suite.T(), received1, core.EventTypeTransferConfirmed, nil)
transfers = client1.GetTokenTransfers(suite.T(), poolID)
assert.Equal(suite.T(), 3, len(transfers))
assert.Equal(suite.T(), suite.connector, transfers[0].Connector)
assert.Equal(suite.T(), core.TokenTransferTypeBurn, transfers[0].Type)
assert.Equal(suite.T(), "", transfers[0].TokenIndex)
assert.Equal(suite.T(), int64(1), transfers[0].Amount.Int().Int64())
e2e.ValidateAccountBalances(suite.T(), client1, poolID, "", map[string]int64{
suite.testState.org1key.Value: 0,
suite.testState.org2key.Value: 0,
})

accounts := client1.GetTokenAccounts(suite.T(), poolID)
assert.Equal(suite.T(), 2, len(accounts))
assert.Equal(suite.T(), suite.testState.org2key.Value, accounts[0].Key)
assert.Equal(suite.T(), suite.testState.org1key.Value, accounts[1].Key)
accounts = client2.GetTokenAccounts(suite.T(), poolID)
assert.Equal(suite.T(), 2, len(accounts))
assert.Equal(suite.T(), suite.testState.org2key.Value, accounts[0].Key)
assert.Equal(suite.T(), suite.testState.org1key.Value, accounts[1].Key)

accountPools := client1.GetTokenAccountPools(suite.T(), suite.testState.org1key.Value)
assert.Equal(suite.T(), *poolID, *accountPools[0].Pool)
accountPools = client2.GetTokenAccountPools(suite.T(), suite.testState.org2key.Value)
assert.Equal(suite.T(), *poolID, *accountPools[0].Pool)
}

0 comments on commit 6577b38

Please sign in to comment.