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

Add E2E test support for ERC20/ERC721 #611

Merged
merged 5 commits into from
Mar 18, 2022
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
8 changes: 8 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,19 @@ jobs:
matrix:
test-suite: [TestEthereumE2ESuite, TestFabricE2ESuite]
blockchain-provider: [geth, fabric]
token-provider: [none, erc1155, erc20_erc721]
database-type: [sqlite3]
exclude:
- blockchain-provider: geth
test-suite: TestFabricE2ESuite
- blockchain-provider: fabric
test-suite: TestEthereumE2ESuite
- blockchain-provider: fabric
token-provider: erc1155
- blockchain-provider: fabric
token-provider: erc20_erc721
nguyer marked this conversation as resolved.
Show resolved Hide resolved
- blockchain-provider: geth
token-provider: none
fail-fast: false
steps:
- uses: actions/checkout@v2
Expand All @@ -53,6 +60,7 @@ jobs:
env:
TEST_SUITE: ${{ matrix.test-suite }}
BLOCKCHAIN_PROVIDER: ${{ matrix.blockchain-provider }}
TOKENS_PROVIDER: ${{ matrix.token-provider }}
DATABASE_TYPE: ${{ matrix.database-type }}
run: ./test/e2e/run.sh

Expand Down
3 changes: 3 additions & 0 deletions db/migrations/postgres/000072_add_tokenpool_info.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
BEGIN;
ALTER TABLE tokenpool DROP COLUMN info;
COMMIT;
3 changes: 3 additions & 0 deletions db/migrations/postgres/000072_add_tokenpool_info.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
BEGIN;
ALTER TABLE tokenpool ADD COLUMN info TEXT;
COMMIT;
1 change: 1 addition & 0 deletions db/migrations/sqlite/000072_add_tokenpool_info.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE tokenpool DROP COLUMN info;
1 change: 1 addition & 0 deletions db/migrations/sqlite/000072_add_tokenpool_info.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE tokenpool ADD COLUMN info TEXT;
4 changes: 4 additions & 0 deletions internal/database/sqlcommon/tokenpool_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var (
"created",
"tx_type",
"tx_id",
"info",
}
tokenPoolFilterFieldMap = map[string]string{
"protocolid": "protocol_id",
Expand Down Expand Up @@ -93,6 +94,7 @@ func (s *SQLCommon) UpsertTokenPool(ctx context.Context, pool *fftypes.TokenPool
Set("state", pool.State).
Set("tx_type", pool.TX.Type).
Set("tx_id", pool.TX.ID).
Set("info", pool.Info).
Where(sq.Eq{"id": pool.ID}),
func() {
s.callbacks.UUIDCollectionNSEvent(database.CollectionTokenPools, fftypes.ChangeEventTypeUpdated, pool.Namespace, pool.ID)
Expand All @@ -119,6 +121,7 @@ func (s *SQLCommon) UpsertTokenPool(ctx context.Context, pool *fftypes.TokenPool
pool.Created,
pool.TX.Type,
pool.TX.ID,
pool.Info,
),
func() {
s.callbacks.UUIDCollectionNSEvent(database.CollectionTokenPools, fftypes.ChangeEventTypeCreated, pool.Namespace, pool.ID)
Expand Down Expand Up @@ -147,6 +150,7 @@ func (s *SQLCommon) tokenPoolResult(ctx context.Context, row *sql.Rows) (*fftype
&pool.Created,
&pool.TX.Type,
&pool.TX.ID,
&pool.Info,
)
if err != nil {
return nil, i18n.WrapError(ctx, err, i18n.MsgDBReadErr, "tokenpool")
Expand Down
3 changes: 3 additions & 0 deletions internal/database/sqlcommon/tokenpool_sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ func TestTokenPoolE2EWithDB(t *testing.T) {
Type: fftypes.TransactionTypeTokenPool,
ID: fftypes.NewUUID(),
},
Info: fftypes.JSONObject{
"pool": "info",
},
}

s.callbacks.On("UUIDCollectionNSEvent", database.CollectionTokenPools, fftypes.ChangeEventTypeCreated, "ns1", poolID, mock.Anything).
Expand Down
19 changes: 8 additions & 11 deletions internal/events/token_pool_created.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ func addPoolDetailsFromPlugin(ffPool *fftypes.TokenPool, pluginPool *tokens.Toke
ffPool.ProtocolID = pluginPool.ProtocolID
ffPool.Connector = pluginPool.Connector
ffPool.Standard = pluginPool.Standard
if pluginPool.TX.ID != nil {
ffPool.TX = pluginPool.TX
}
if pluginPool.Symbol != "" {
if ffPool.Symbol == "" {
ffPool.Symbol = pluginPool.Symbol
Expand All @@ -42,12 +45,6 @@ func addPoolDetailsFromPlugin(ffPool *fftypes.TokenPool, pluginPool *tokens.Toke
}
}
ffPool.Info = pluginPool.Info
if pluginPool.TransactionID != nil {
ffPool.TX = fftypes.TransactionRef{
Type: fftypes.TransactionTypeTokenPool,
ID: pluginPool.TransactionID,
}
}
return nil
}

Expand Down Expand Up @@ -95,7 +92,7 @@ func (em *eventManager) shouldConfirm(ctx context.Context, pool *tokens.TokenPoo
return existingPool, err
}
if err = addPoolDetailsFromPlugin(existingPool, pool); err != nil {
log.L(ctx).Errorf("Error processing pool for transaction '%s' (%s) - ignoring", pool.TransactionID, err)
log.L(ctx).Errorf("Error processing pool for transaction '%s' (%s) - ignoring", pool.TX.ID, err)
return nil, nil
}

Expand All @@ -112,7 +109,7 @@ func (em *eventManager) shouldConfirm(ctx context.Context, pool *tokens.TokenPoo
}

func (em *eventManager) shouldAnnounce(ctx context.Context, pool *tokens.TokenPool) (announcePool *fftypes.TokenPool, err error) {
op, err := em.findTXOperation(ctx, pool.TransactionID, fftypes.OpTypeTokenCreatePool)
op, err := em.findTXOperation(ctx, pool.TX.ID, fftypes.OpTypeTokenCreatePool)
if err != nil {
return nil, err
} else if op == nil {
Expand All @@ -121,12 +118,12 @@ func (em *eventManager) shouldAnnounce(ctx context.Context, pool *tokens.TokenPo

announcePool, err = txcommon.RetrieveTokenPoolCreateInputs(ctx, op)
if err != nil || announcePool.ID == nil || announcePool.Namespace == "" || announcePool.Name == "" {
log.L(ctx).Errorf("Error loading pool info for transaction '%s' (%s) - ignoring: %v", pool.TransactionID, err, op.Input)
log.L(ctx).Errorf("Error loading pool info for transaction '%s' (%s) - ignoring: %v", pool.TX.ID, err, op.Input)
return nil, nil
}

if err = addPoolDetailsFromPlugin(announcePool, pool); err != nil {
log.L(ctx).Errorf("Error processing pool for transaction '%s' (%s) - ignoring", pool.TransactionID, err)
log.L(ctx).Errorf("Error processing pool for transaction '%s' (%s) - ignoring", pool.TX.ID, err)
return nil, nil
}
return announcePool, nil
Expand Down Expand Up @@ -157,7 +154,7 @@ func (em *eventManager) TokenPoolCreated(ti tokens.Plugin, pool *tokens.TokenPoo
batchID = msg.BatchID // trigger rewind after completion of database transaction
}
return em.confirmPool(ctx, existingPool, &pool.Event, pool.Event.BlockchainTXID)
} else if pool.TransactionID == nil {
} else if pool.TX.ID == nil {
// TransactionID is required if the pool doesn't exist yet
// (but it may be omitted when activating a pool that was received via definition broadcast)
log.L(em.ctx).Errorf("Invalid token pool transaction - ID is nil")
Expand Down
116 changes: 71 additions & 45 deletions internal/events/token_pool_created_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ func TestTokenPoolCreatedIgnore(t *testing.T) {
operations := []*fftypes.Operation{}
info := fftypes.JSONObject{"some": "info"}
pool := &tokens.TokenPool{
Type: fftypes.TokenTypeFungible,
ProtocolID: "123",
TransactionID: txID,
Connector: "erc1155",
Type: fftypes.TokenTypeFungible,
ProtocolID: "123",
TX: fftypes.TransactionRef{
ID: txID,
Type: fftypes.TransactionTypeTokenPool,
},
Connector: "erc1155",
Event: blockchain.Event{
BlockchainTXID: "0xffffeeee",
ProtocolID: "tx1",
Expand All @@ -72,10 +75,9 @@ func TestTokenPoolCreatedIgnoreNoTX(t *testing.T) {

info := fftypes.JSONObject{"some": "info"}
pool := &tokens.TokenPool{
Type: fftypes.TokenTypeFungible,
ProtocolID: "123",
TransactionID: nil,
Connector: "erc1155",
Type: fftypes.TokenTypeFungible,
ProtocolID: "123",
Connector: "erc1155",
Event: blockchain.Event{
BlockchainTXID: "0xffffeeee",
ProtocolID: "tx1",
Expand All @@ -102,13 +104,16 @@ func TestTokenPoolCreatedConfirm(t *testing.T) {
info1 := fftypes.JSONObject{"pool": "info"}
info2 := fftypes.JSONObject{"block": "info"}
chainPool := &tokens.TokenPool{
Type: fftypes.TokenTypeFungible,
ProtocolID: "123",
Connector: "erc1155",
TransactionID: txID,
Standard: "ERC1155",
Symbol: "FFT",
Info: info1,
Type: fftypes.TokenTypeFungible,
ProtocolID: "123",
Connector: "erc1155",
TX: fftypes.TransactionRef{
ID: txID,
Type: fftypes.TransactionTypeTokenPool,
},
Standard: "ERC1155",
Symbol: "FFT",
Info: info1,
Event: blockchain.Event{
BlockchainTXID: "0xffffeeee",
Name: "TokenPool",
Expand Down Expand Up @@ -170,10 +175,13 @@ func TestTokenPoolCreatedAlreadyConfirmed(t *testing.T) {
txID := fftypes.NewUUID()
info := fftypes.JSONObject{"some": "info"}
chainPool := &tokens.TokenPool{
Type: fftypes.TokenTypeFungible,
ProtocolID: "123",
Connector: "erc1155",
TransactionID: txID,
Type: fftypes.TokenTypeFungible,
ProtocolID: "123",
Connector: "erc1155",
TX: fftypes.TransactionRef{
ID: txID,
Type: fftypes.TransactionTypeTokenPool,
},
Event: blockchain.Event{
BlockchainTXID: "0xffffeeee",
ProtocolID: "tx1",
Expand Down Expand Up @@ -208,11 +216,14 @@ func TestTokenPoolCreatedConfirmFailBadSymbol(t *testing.T) {
txID := fftypes.NewUUID()
info := fftypes.JSONObject{"some": "info"}
chainPool := &tokens.TokenPool{
Type: fftypes.TokenTypeFungible,
ProtocolID: "123",
Connector: "erc1155",
TransactionID: txID,
Symbol: "ETH",
Type: fftypes.TokenTypeFungible,
ProtocolID: "123",
Connector: "erc1155",
TX: fftypes.TransactionRef{
ID: txID,
Type: fftypes.TransactionTypeTokenPool,
},
Symbol: "ETH",
Event: blockchain.Event{
BlockchainTXID: "0xffffeeee",
ProtocolID: "tx1",
Expand Down Expand Up @@ -253,10 +264,13 @@ func TestTokenPoolCreatedMigrate(t *testing.T) {
txID := fftypes.NewUUID()
info := fftypes.JSONObject{"some": "info"}
chainPool := &tokens.TokenPool{
Type: fftypes.TokenTypeFungible,
ProtocolID: "123",
Connector: "magic-tokens",
TransactionID: txID,
Type: fftypes.TokenTypeFungible,
ProtocolID: "123",
Connector: "magic-tokens",
TX: fftypes.TransactionRef{
ID: txID,
Type: fftypes.TransactionTypeTokenPool,
},
Event: blockchain.Event{
BlockchainTXID: "0xffffeeee",
ProtocolID: "tx1",
Expand Down Expand Up @@ -497,10 +511,13 @@ func TestTokenPoolCreatedAnnounce(t *testing.T) {
}
info := fftypes.JSONObject{"some": "info"}
pool := &tokens.TokenPool{
Type: fftypes.TokenTypeFungible,
ProtocolID: "123",
TransactionID: txID,
Connector: "erc1155",
Type: fftypes.TokenTypeFungible,
ProtocolID: "123",
TX: fftypes.TransactionRef{
ID: txID,
Type: fftypes.TransactionTypeTokenPool,
},
Connector: "erc1155",
Event: blockchain.Event{
BlockchainTXID: "0xffffeeee",
ProtocolID: "tx1",
Expand Down Expand Up @@ -539,10 +556,13 @@ func TestTokenPoolCreatedAnnounceBadOpInputID(t *testing.T) {
}
info := fftypes.JSONObject{"some": "info"}
pool := &tokens.TokenPool{
Type: fftypes.TokenTypeFungible,
ProtocolID: "123",
TransactionID: txID,
Connector: "erc1155",
Type: fftypes.TokenTypeFungible,
ProtocolID: "123",
TX: fftypes.TransactionRef{
ID: txID,
Type: fftypes.TransactionTypeTokenPool,
},
Connector: "erc1155",
Event: blockchain.Event{
BlockchainTXID: "0xffffeeee",
ProtocolID: "tx1",
Expand Down Expand Up @@ -577,10 +597,13 @@ func TestTokenPoolCreatedAnnounceBadOpInputNS(t *testing.T) {
}
info := fftypes.JSONObject{"some": "info"}
pool := &tokens.TokenPool{
Type: fftypes.TokenTypeFungible,
ProtocolID: "123",
TransactionID: txID,
Connector: "erc1155",
Type: fftypes.TokenTypeFungible,
ProtocolID: "123",
TX: fftypes.TransactionRef{
ID: txID,
Type: fftypes.TransactionTypeTokenPool,
},
Connector: "erc1155",
Event: blockchain.Event{
BlockchainTXID: "0xffffeeee",
ProtocolID: "tx1",
Expand Down Expand Up @@ -618,11 +641,14 @@ func TestTokenPoolCreatedAnnounceBadSymbol(t *testing.T) {
}
info := fftypes.JSONObject{"some": "info"}
pool := &tokens.TokenPool{
Type: fftypes.TokenTypeFungible,
ProtocolID: "123",
TransactionID: txID,
Connector: "erc1155",
Symbol: "ETH",
Type: fftypes.TokenTypeFungible,
ProtocolID: "123",
TX: fftypes.TransactionRef{
ID: txID,
Type: fftypes.TransactionTypeTokenPool,
},
Connector: "erc1155",
Symbol: "ETH",
Event: blockchain.Event{
BlockchainTXID: "0xffffeeee",
ProtocolID: "tx1",
Expand Down
Loading