Repository: trustwallet/blockatlas
Pull request #1114 (2020-05-20 13:26:59)

Revert "[BulkInsert] Use gorm-bulk-insert instead of BulkCreate"
Reverts trustwallet/blockatlas#1113


Patch:
diff --git a/db/db.go b/db/db.go
index 6d62678..fe79c96 100644
--- a/db/db.go
+++ b/db/db.go
@@ -1,14 +1,11 @@
 package db
 
 import (
-	"errors"
 	"github.com/jinzhu/gorm"
-	gormbulk "github.com/t-tiger/gorm-bulk-insert"
 	"github.com/trustwallet/blockatlas/db/models"
 	"github.com/trustwallet/blockatlas/pkg/logger"
 	"go.elastic.co/apm/module/apmgorm"
 	_ "go.elastic.co/apm/module/apmgorm/dialects/postgres"
-	"reflect"
 	"time"
 )
 
@@ -16,8 +13,6 @@ type Instance struct {
 	Gorm *gorm.DB
 }
 
-const batchCount = 3000
-
 func New(uri, env string) (*Instance, error) {
 	var (
 		g   *gorm.DB
@@ -65,48 +60,3 @@ func RestoreConnectionWorker(database *Instance, timeout time.Duration, uri stri
 		time.Sleep(timeout)
 	}
 }
-
-func bulkInsert(db *gorm.DB, dbModels interface{}) error {
-	interfaceSlice, err := getInterfaceSlice(dbModels)
-	if err != nil {
-		return err
-	}
-	batchList := getInterfaceSliceBatch(interfaceSlice, batchCount)
-	for _, batch := range batchList {
-		err := gormbulk.BulkInsert(db, batch, len(batch))
-		if err != nil {
-			return err
-		}
-	}
-	return nil
-}
-
-func getInterfaceSlice(slice interface{}) ([]interface{}, error) {
-	s := reflect.ValueOf(slice)
-	if s.Kind() != reflect.Slice {
-		return nil, errors.New("InterfaceSlice() given a non-slice type")
-	}
-
-	ret := make([]interface{}, s.Len())
-
-	for i := 0; i < s.Len(); i++ {
-		ret[i] = s.Index(i).Interface()
-	}
-
-	return ret, nil
-}
-
-func getInterfaceSliceBatch(values []interface{}, sizeUint uint) [][]interface{} {
-	size := int(sizeUint)
-	resultLength := (len(values) + size - 1) / size
-	result := make([][]interface{}, resultLength)
-	lo, hi := 0, size
-	for i := range result {
-		if hi > len(values) {
-			hi = len(values)
-		}
-		result[i] = values[lo:hi:hi]
-		lo, hi = hi, hi+size
-	}
-	return result
-}
diff --git a/db/models/subscriptions.go b/db/models/subscriptions.go
index 56eafb1..016e862 100644
--- a/db/models/subscriptions.go
+++ b/db/models/subscriptions.go
@@ -11,6 +11,6 @@ type Subscription struct {
 type SubscriptionData struct {
 	ID             uint   `gorm:"primary_key;"`
 	SubscriptionId uint   `gorm:"primary_key; column:subscription_id; auto_increment:false"`
-	Coin           *uint  `gorm:"primary_key; column:coin; auto_increment:false"`
+	Coin           uint   `gorm:"primary_key; column:coin; auto_increment:false"`
 	Address        string `gorm:"primary_key; column:address; type:varchar(128)"`
 }
diff --git a/db/subscriptions.go b/db/subscriptions.go
index e5c0c53..917fc40 100644
--- a/db/subscriptions.go
+++ b/db/subscriptions.go
@@ -2,13 +2,17 @@ package db
 
 import (
 	"context"
+	"fmt"
 	"github.com/trustwallet/blockatlas/db/models"
 	"github.com/trustwallet/blockatlas/pkg/errors"
 	"go.elastic.co/apm/module/apmgorm"
 	"strconv"
+	"strings"
 	"time"
 )
 
+const rawBulkInsert = `INSERT INTO subscription_data(subscription_id, coin, address) VALUES %s ON CONFLICT DO NOTHING`
+
 func (i *Instance) GetSubscriptionData(coin uint, addresses []string, ctx context.Context) ([]models.SubscriptionData, error) {
 	if len(addresses) == 0 {
 		return nil, errors.E("Empty addresses")
@@ -61,10 +65,7 @@ func (i *Instance) AddSubscriptions(id uint, subscriptions []models.Subscription
 			txInstance.Gorm.Rollback()
 			return err
 		}
-
-		db := txInstance.Gorm.Set("gorm:insert_option", "ON CONFLICT DO NOTHING")
-		err = bulkInsert(db, subscriptions)
-
+		err = txInstance.BulkCreate(subscriptions)
 	} else {
 		err = txInstance.AddToExistingSubscription(id, subscriptions)
 	}
@@ -90,8 +91,7 @@ func (i *Instance) AddToExistingSubscription(id uint, subscriptions []models.Sub
 
 	updateList, deleteList := getSubscriptionsToDeleteAndUpdate(existingData, subscriptions)
 	if len(updateList) > 0 {
-		db := i.Gorm.Set("gorm:insert_option", "ON CONFLICT DO NOTHING")
-		if err := bulkInsert(db, updateList); err != nil {
+		if err := i.BulkCreate(updateList); err != nil {
 			return err
 		}
 	}
@@ -136,6 +136,29 @@ func (i *Instance) DeleteSubscriptions(subscriptions []models.SubscriptionData)
 	return nil
 }
 
+func (i *Instance) BulkCreate(dataList []models.SubscriptionData) error {
+	var (
+		valueStrings []string
+		valueArgs    []interface{}
+	)
+
+	for _, d := range dataList {
+		valueStrings = append(valueStrings, "(?, ?, ?)")
+
+		valueArgs = append(valueArgs, d.SubscriptionId)
+		valueArgs = append(valueArgs, d.Coin)
+		valueArgs = append(valueArgs, d.Address)
+	}
+
+	smt := fmt.Sprintf(rawBulkInsert, strings.Join(valueStrings, ","))
+
+	if err := i.Gorm.Exec(smt, valueArgs...).Error; err != nil {
+		return err
+	}
+
+	return nil
+}
+
 func getSubscriptionsToDeleteAndUpdate(existing, new []models.SubscriptionData) (subToUpdate, subToDelete []models.SubscriptionData) {
 	for _, n := range new {
 		if !containSubscription(n, existing) {
diff --git a/go.mod b/go.mod
index c00f0de..443ac60 100644
--- a/go.mod
+++ b/go.mod
@@ -36,7 +36,6 @@ require (
 	github.com/stretchr/testify v1.5.1
 	github.com/swaggo/gin-swagger v1.2.0
 	github.com/swaggo/swag v1.6.5
-	github.com/t-tiger/gorm-bulk-insert v1.3.0
 	github.com/trustwallet/ens-coincodec v1.0.5
 	go.elastic.co/apm v1.8.0
 	go.elastic.co/apm/module/apmgin v1.8.0
diff --git a/go.sum b/go.sum
index 287d794..4d2b753 100644
--- a/go.sum
+++ b/go.sum
@@ -236,7 +236,6 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
 github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
 github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
 github.com/jinzhu/gorm v1.9.10/go.mod h1:Kh6hTsSGffh4ui079FHrR5Gg+5D0hgihqDcsDN2BBJY=
-github.com/jinzhu/gorm v1.9.11/go.mod h1:bu/pK8szGZ2puuErfU0RwyeNdsf3e6nCX/noXaVxkfw=
 github.com/jinzhu/gorm v1.9.12 h1:Drgk1clyWT9t9ERbzHza6Mj/8FY/CqMyVzOiHviMo6Q=
 github.com/jinzhu/gorm v1.9.12/go.mod h1:vhTjlKSJUTWNtcbQtrMBFCxy7eXTzeCAzfL5fBZT/Qs=
 github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
@@ -287,7 +286,6 @@ github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd
 github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
 github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
 github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
-github.com/mattn/go-sqlite3 v1.11.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
 github.com/mattn/go-sqlite3 v2.0.1+incompatible h1:xQ15muvnzGBHpIpdrNi1DA5x0+TcBZzsIDwmw9uTHzw=
 github.com/mattn/go-sqlite3 v2.0.1+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
 github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
@@ -421,8 +419,6 @@ github.com/swaggo/gin-swagger v1.2.0/go.mod h1:qlH2+W7zXGZkczuL+r2nEBR2JTT+/lX05
 github.com/swaggo/swag v1.5.1/go.mod h1:1Bl9F/ZBpVWh22nY0zmYyASPO1lI/zIwRDrpZU+tv8Y=
 github.com/swaggo/swag v1.6.5 h1:2C+t+xyK6p1sujqncYO/VnMvPZcBJjNdKKyxbOdAW8o=
 github.com/swaggo/swag v1.6.5/go.mod h1:Y7ZLSS0d0DdxhWGVhQdu+Bu1QhaF5k0RD7FKdiAykeY=
-github.com/t-tiger/gorm-bulk-insert v1.3.0 h1:9k7BaVEhw/3fsvh6GTOBwJ2RXk3asc5xs5m6hwozq20=
-github.com/t-tiger/gorm-bulk-insert v1.3.0/go.mod h1:ruDlk8xDl+8sX4bA7PQuYly9YEb3pbp1eP2LCyeRrFY=
 github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
 github.com/trustwallet/ens-coincodec v1.0.5 h1:rdebDQYHqNjv+yUdtMf3DXyMgJpEJSI2DSbC1GUFuyk=
 github.com/trustwallet/ens-coincodec v1.0.5/go.mod h1:hTZCauB3S2Gt9M3FiRNva+xpLJXFqLyODKFF+UvH1lw=
diff --git a/services/observer/notifier/notifier.go b/services/observer/notifier/notifier.go
index be4834d..898242b 100644
--- a/services/observer/notifier/notifier.go
+++ b/services/observer/notifier/notifier.go
@@ -61,7 +61,7 @@ func RunNotifier(database *db.Instance, delivery amqp.Delivery) {
 	for _, data := range subscriptionsDataList {
 		go buildAndPostMessage(
 			blockTransactions,
-			blockatlas.Subscription{Coin: *data.Coin, Address: data.Address, Id: data.SubscriptionId},
+			blockatlas.Subscription{Coin: data.Coin, Address: data.Address, Id: data.SubscriptionId},
 			&wg, ctx)
 	}
 	wg.Wait()
diff --git a/services/observer/subscriber/subscriber.go b/services/observer/subscriber/subscriber.go
index d5f9e88..1100b43 100644
--- a/services/observer/subscriber/subscriber.go
+++ b/services/observer/subscriber/subscriber.go
@@ -57,8 +57,7 @@ func RunSubscriber(database *db.Instance, delivery amqp.Delivery) {
 func ToSubscriptionData(sub []blockatlas.Subscription) []models.SubscriptionData {
 	data := make([]models.SubscriptionData, 0, len(sub))
 	for _, s := range sub {
-		coin := s.Coin
-		data = append(data, models.SubscriptionData{Coin: &coin, Address: s.Address, SubscriptionId: s.Id})
+		data = append(data, models.SubscriptionData{Coin: s.Coin, Address: s.Address, SubscriptionId: s.Id})
 	}
 	return data
 }


Test patch:
diff --git a/db/subscritions_test.go b/db/subscritions_test.go
index 8f15008..274ceec 100644
--- a/db/subscritions_test.go
+++ b/db/subscritions_test.go
@@ -3,32 +3,31 @@ package db
 import (
 	"github.com/stretchr/testify/assert"
 	"github.com/trustwallet/blockatlas/db/models"
-	"github.com/trustwallet/blockatlas/tests/integration/setup/testdata"
 	"testing"
 )
 
 func TestGetSubscriptionsToDeleteAndUpdate(t *testing.T) {
 	oldSubscriptions := []models.SubscriptionData{{
 		SubscriptionId: 1,
-		Coin:           &testdata.EthCoin.ID,
+		Coin:           60,
 		Address:        "A",
 	}, {
 		SubscriptionId: 1,
-		Coin:           &testdata.EthCoin.ID,
+		Coin:           60,
 		Address:        "B",
 	}, {
 		SubscriptionId: 1,
-		Coin:           &testdata.EthCoin.ID,
+		Coin:           60,
 		Address:        "C",
 	}}
 
 	newSubscription := []models.SubscriptionData{{
 		SubscriptionId: 1,
-		Coin:           &testdata.EthCoin.ID,
+		Coin:           60,
 		Address:        "B",
 	}, {
 		SubscriptionId: 1,
-		Coin:           &testdata.EthCoin.ID,
+		Coin:           60,
 		Address:        "C",
 	}}
 
@@ -39,25 +38,25 @@ func TestGetSubscriptionsToDeleteAndUpdate(t *testing.T) {
 
 	oldSubscriptions = []models.SubscriptionData{{
 		SubscriptionId: 1,
-		Coin:           &testdata.EthCoin.ID,
+		Coin:           60,
 		Address:        "A",
 	}, {
 		SubscriptionId: 1,
-		Coin:           &testdata.EthCoin.ID,
+		Coin:           60,
 		Address:        "B",
 	}, {
 		SubscriptionId: 1,
-		Coin:           &testdata.EthCoin.ID,
+		Coin:           60,
 		Address:        "C",
 	}, {
 		SubscriptionId: 1,
-		Coin:           &testdata.EthCoin.ID,
+		Coin:           60,
 		Address:        "D",
 	}}
 
 	newSubscription = []models.SubscriptionData{{
 		SubscriptionId: 1,
-		Coin:           &testdata.EthCoin.ID,
+		Coin:           60,
 		Address:        "E",
 	}}
 
@@ -67,21 +66,21 @@ func TestGetSubscriptionsToDeleteAndUpdate(t *testing.T) {
 
 	oldSubscriptions = []models.SubscriptionData{{
 		SubscriptionId: 1,
-		Coin:           &testdata.EthCoin.ID,
+		Coin:           60,
 		Address:        "A",
 	}, {
 		SubscriptionId: 1,
-		Coin:           &testdata.EthCoin.ID,
+		Coin:           60,
 		Address:        "B",
 	}}
 
 	newSubscription = []models.SubscriptionData{{
 		SubscriptionId: 1,
-		Coin:           &testdata.EthCoin.ID,
+		Coin:           60,
 		Address:        "A",
 	}, {
 		SubscriptionId: 1,
-		Coin:           &testdata.EthCoin.ID,
+		Coin:           60,
 		Address:        "B",
 	}}
 
diff --git a/services/observer/subscriber/subscriber_test.go b/services/observer/subscriber/subscriber_test.go
index b8aefe5..713b879 100644
--- a/services/observer/subscriber/subscriber_test.go
+++ b/services/observer/subscriber/subscriber_test.go
@@ -4,30 +4,29 @@ import (
 	"github.com/stretchr/testify/assert"
 	"github.com/trustwallet/blockatlas/db/models"
 	"github.com/trustwallet/blockatlas/pkg/blockatlas"
-	"github.com/trustwallet/blockatlas/tests/integration/setup/testdata"
 	"testing"
 )
 
 func TestToSubscriptionData(t *testing.T) {
 	sub := blockatlas.Subscription{
-		Coin:    testdata.EthCoin.ID,
+		Coin:    60,
 		Address: "A",
 		Id:      1,
 	}
 	sub2 := blockatlas.Subscription{
-		Coin:    testdata.EthCoin.ID,
+		Coin:    60,
 		Address: "B",
 		Id:      2,
 	}
 
 	expectedModel := models.SubscriptionData{
 		SubscriptionId: 1,
-		Coin:           &testdata.EthCoin.ID,
+		Coin:           60,
 		Address:        "A",
 	}
 	expectedModel1 := models.SubscriptionData{
 		SubscriptionId: 2,
-		Coin:           &testdata.EthCoin.ID,
+		Coin:           60,
 		Address:        "B",
 	}
 
diff --git a/tests/integration/db_test/subscriptions_test.go b/tests/integration/db_test/subscriptions_test.go
index 27ef7db..0cafda6 100644
--- a/tests/integration/db_test/subscriptions_test.go
+++ b/tests/integration/db_test/subscriptions_test.go
@@ -9,8 +9,6 @@ import (
 	"github.com/trustwallet/blockatlas/pkg/blockatlas"
 	"github.com/trustwallet/blockatlas/services/observer/subscriber"
 	"github.com/trustwallet/blockatlas/tests/integration/setup"
-	"github.com/trustwallet/blockatlas/tests/integration/setup/testdata"
-	"sort"
 	"testing"
 	"time"
 )
@@ -22,10 +20,9 @@ func TestDb_AddSubscriptionsBulk(t *testing.T) {
 	id := uint(1)
 
 	for i := 0; i < 100; i++ {
-		coin := uint(i)
 		subscriptions = append(subscriptions, models.SubscriptionData{
 			SubscriptionId: id,
-			Coin:           &coin,
+			Coin:           uint(i),
 			Address:        "testAddrtestAddrtestAddrtestAddrtestAddrtestAddrtestAddrtestAddrtestAddrtestAddr",
 		})
 	}
@@ -44,25 +41,21 @@ func TestDb_AddSubscriptions(t *testing.T) {
 	var subscriptions []models.SubscriptionData
 
 	id := uint(1)
-
-	c1 := uint(60)
-	c2 := uint(61)
-	c3 := uint(62)
 	subscriptions = append(subscriptions, models.SubscriptionData{
 		SubscriptionId: id,
-		Coin:           &c1,
+		Coin:           60,
 		Address:        "testAddr",
 	})
 
 	subscriptions = append(subscriptions, models.SubscriptionData{
 		SubscriptionId: id,
-		Coin:           &c2,
+		Coin:           61,
 		Address:        "testAddr2",
 	})
 
 	subscriptions = append(subscriptions, models.SubscriptionData{
 		SubscriptionId: id,
-		Coin:           &c3,
+		Coin:           62,
 		Address:        "testAddr3",
 	})
 
@@ -100,19 +93,19 @@ func TestDb_AddSubscriptionsWithRewrite(t *testing.T) {
 	var subscriptions []models.SubscriptionData
 	subscriptions = append(subscriptions, models.SubscriptionData{
 		SubscriptionId: id,
-		Coin:           &testdata.EthCoin.ID,
+		Coin:           60,
 		Address:        "testAddr",
 	})
 
 	subscriptions = append(subscriptions, models.SubscriptionData{
 		SubscriptionId: id,
-		Coin:           &testdata.BnbCoin.ID,
+		Coin:           714,
 		Address:        "testAddr",
 	})
 
 	subscriptions = append(subscriptions, models.SubscriptionData{
 		SubscriptionId: id,
-		Coin:           &testdata.XrpCoin.ID,
+		Coin:           144,
 		Address:        "testAddr",
 	})
 
@@ -144,19 +137,19 @@ func TestDb_AddSubscriptionsWithRewrite(t *testing.T) {
 
 	subscriptions = append(subscriptions, models.SubscriptionData{
 		SubscriptionId: id,
-		Coin:           &testdata.EthCoin.ID,
+		Coin:           60,
 		Address:        "testAddr2",
 	})
 
 	subscriptions = append(subscriptions, models.SubscriptionData{
 		SubscriptionId: id,
-		Coin:           &testdata.BnbCoin.ID,
+		Coin:           714,
 		Address:        "testAddr2",
 	})
 
 	subscriptions = append(subscriptions, models.SubscriptionData{
 		SubscriptionId: id,
-		Coin:           &testdata.XrpCoin.ID,
+		Coin:           144,
 		Address:        "testAddr2",
 	})
 
@@ -263,19 +256,19 @@ func TestDb_DeleteSubscriptions(t *testing.T) {
 	id := uint(1)
 	subscriptions = append(subscriptions, models.SubscriptionData{
 		SubscriptionId: id,
-		Coin:           &testdata.EthCoin.ID,
+		Coin:           60,
 		Address:        "testAddr",
 	})
 
 	subscriptions = append(subscriptions, models.SubscriptionData{
 		SubscriptionId: id,
-		Coin:           &testdata.BnbCoin.ID,
+		Coin:           714,
 		Address:        "testAddr2",
 	})
 
 	subscriptions = append(subscriptions, models.SubscriptionData{
 		SubscriptionId: id,
-		Coin:           &testdata.XrpCoin.ID,
+		Coin:           144,
 		Address:        "testAddr3",
 	})
 
@@ -338,19 +331,19 @@ func TestDeleteAll(t *testing.T) {
 	id := uint(1)
 	subscriptions = append(subscriptions, models.SubscriptionData{
 		SubscriptionId: id,
-		Coin:           &testdata.EthCoin.ID,
+		Coin:           60,
 		Address:        "testAddr",
 	})
 
 	subscriptions = append(subscriptions, models.SubscriptionData{
 		SubscriptionId: id,
-		Coin:           &testdata.BnbCoin.ID,
+		Coin:           714,
 		Address:        "testAddr2",
 	})
 
 	subscriptions = append(subscriptions, models.SubscriptionData{
 		SubscriptionId: id,
-		Coin:           &testdata.XrpCoin.ID,
+		Coin:           144,
 		Address:        "testAddr3",
 	})
 	assert.Nil(t, database.AddSubscriptions(id, subscriptions, context.Background()))
@@ -397,7 +390,7 @@ func TestDb_DuplicateEntries(t *testing.T) {
 	for i := 0; i < 10; i++ {
 		subscriptions = append(subscriptions, models.SubscriptionData{
 			SubscriptionId: id,
-			Coin:           &testdata.EthCoin.ID,
+			Coin:           60,
 			Address:        "testAddr",
 		})
 	}
@@ -414,9 +407,8 @@ func TestDb_DuplicateEntries(t *testing.T) {
 func TestDb_FindSubscriptions_Multiple(t *testing.T) {
 	setup.CleanupPgContainer(database.Gorm)
 	var subscriptions []models.SubscriptionData
-
 	subscriptions = append(subscriptions, models.SubscriptionData{
-		Coin:    &testdata.EthCoin.ID,
+		Coin:    60,
 		Address: "testAddr",
 	})
 
@@ -432,10 +424,6 @@ func TestDb_FindSubscriptions_Multiple(t *testing.T) {
 	assert.Nil(t, err)
 	assert.Equal(t, 5, len(subs))
 
-	sort.Slice(subs, func(i, j int) bool {
-		return subs[i].SubscriptionId < subs[j].SubscriptionId
-	})
-
 	for i := 0; i < 5; i++ {
 		assert.Equal(t, uint(i)+1, subs[i].SubscriptionId)
 	}
@@ -445,7 +433,7 @@ func TestDb_AddToExisting(t *testing.T) {
 	setup.CleanupPgContainer(database.Gorm)
 	var subscriptions []models.SubscriptionData
 	subscriptions = append(subscriptions, models.SubscriptionData{
-		Coin:    &testdata.EthCoin.ID,
+		Coin:    60,
 		Address: "testAddr",
 	})
 
@@ -479,11 +467,11 @@ func TestDb_UpdatedAt(t *testing.T) {
 	setup.CleanupPgContainer(database.Gorm)
 	var subscriptions []models.SubscriptionData
 	subscriptions = append(subscriptions, models.SubscriptionData{
-		SubscriptionId: 1,
-		Coin:           &testdata.EthCoin.ID,
-		Address:        "testAddr",
+		Coin:    60,
+		Address: "testAddr",
 	})
 
+	subscriptions[0].SubscriptionId = uint(1)
 	assert.Nil(t, database.AddSubscriptions(uint(1), subscriptions, context.Background()))
 	subs, err := database.GetSubscriptionData(60, []string{"testAddr"}, context.Background())
 	assert.Nil(t, err)
@@ -497,9 +485,8 @@ func TestDb_UpdatedAt(t *testing.T) {
 	assert.Greater(t, existingSub.UpdatedAt.Unix(), time.Now().Unix()-120)
 
 	subscriptions = append(subscriptions, models.SubscriptionData{
-		SubscriptionId: 1,
-		Coin:           &testdata.BnbCoin.ID,
-		Address:        "newtestAddr",
+		Coin:    714,
+		Address: "newtestAddr",
 	})
 
 	assert.Nil(t, database.AddSubscriptions(uint(1), subscriptions, context.Background()))
@@ -512,11 +499,12 @@ func TestDb_UpdatedAt(t *testing.T) {
 	assert.Greater(t, time.Now().Unix(), existingSub2.UpdatedAt.Unix())
 	assert.Greater(t, existingSub2.UpdatedAt.Unix(), time.Now().Unix()-120)
 	assert.Greater(t, existingSub2.UpdatedAt.Unix(), existingSub.UpdatedAt.Unix())
+
 }
 
 func containSub(sub models.SubscriptionData, list []models.SubscriptionData) bool {
 	for _, s := range list {
-		if sub.Address == s.Address && *sub.Coin == *s.Coin && sub.SubscriptionId == s.SubscriptionId {
+		if sub.Address == s.Address && sub.Coin == s.Coin && sub.SubscriptionId == s.SubscriptionId {
 			return true
 		}
 	}
diff --git a/tests/integration/observer_test/full_flow_test.go b/tests/integration/observer_test/full_flow_test.go
index 24b4173..29cce3a 100644
--- a/tests/integration/observer_test/full_flow_test.go
+++ b/tests/integration/observer_test/full_flow_test.go
@@ -14,7 +14,6 @@ import (
 	"github.com/trustwallet/blockatlas/services/observer/notifier"
 	"github.com/trustwallet/blockatlas/services/observer/parser"
 	"github.com/trustwallet/blockatlas/tests/integration/setup"
-	"github.com/trustwallet/blockatlas/tests/integration/setup/testdata"
 	"go.uber.org/atomic"
 	"testing"
 	"time"
@@ -26,8 +25,7 @@ var (
 
 func TestFullFlow(t *testing.T) {
 	setup.CleanupPgContainer(database.Gorm)
-
-	err := database.AddSubscriptions(1, []models.SubscriptionData{{Coin: &testdata.EthCoin.ID, Address: "testAddress", SubscriptionId: 1}}, context.Background())
+	err := database.AddSubscriptions(1, []models.SubscriptionData{{Coin: 60, Address: "testAddress", SubscriptionId: 1}}, context.Background())
 	assert.Nil(t, err)
 
 	ctx, cancel := context.WithCancel(context.Background())
diff --git a/tests/integration/observer_test/notifier_test.go b/tests/integration/observer_test/notifier_test.go
index 9203544..0f6a1ab 100644
--- a/tests/integration/observer_test/notifier_test.go
+++ b/tests/integration/observer_test/notifier_test.go
@@ -13,7 +13,6 @@ import (
 	"github.com/trustwallet/blockatlas/pkg/blockatlas"
 	"github.com/trustwallet/blockatlas/services/observer/notifier"
 	"github.com/trustwallet/blockatlas/tests/integration/setup"
-	"github.com/trustwallet/blockatlas/tests/integration/setup/testdata"
 	"testing"
 	"time"
 )
@@ -45,7 +44,7 @@ var (
 func TestNotifier(t *testing.T) {
 	setup.CleanupPgContainer(database.Gorm)
 
-	err := database.AddSubscriptions(1, []models.SubscriptionData{{Coin: &testdata.BnbCoin.ID, Address: "tbnb1ttyn4csghfgyxreu7lmdu3lcplhqhxtzced45a", SubscriptionId: 1}}, context.Background())
+	err := database.AddSubscriptions(1, []models.SubscriptionData{{Coin: 714, Address: "tbnb1ttyn4csghfgyxreu7lmdu3lcplhqhxtzced45a", SubscriptionId: 1}}, context.Background())
 	assert.Nil(t, err)
 
 	err = produceTxs(txs)
diff --git a/tests/integration/observer_test/subscriber_test.go b/tests/integration/observer_test/subscriber_test.go
index 80eb667..b7e9ac1 100644
--- a/tests/integration/observer_test/subscriber_test.go
+++ b/tests/integration/observer_test/subscriber_test.go
@@ -60,7 +60,7 @@ func TestSubscriberAddSubscription(t *testing.T) {
 		result, err := database.GetSubscriptionData(wanted.Coin, []string{wanted.Address}, context.Background())
 		assert.Nil(t, err)
 		assert.Equal(t, result[0].SubscriptionId, wanted.Id)
-		assert.Equal(t, wanted.Coin, *result[0].Coin)
+		assert.Equal(t, result[0].Coin, wanted.Coin)
 		assert.Equal(t, result[0].Address, wanted.Address)
 	}
 }
@@ -91,21 +91,18 @@ func TestSubscriber_UpdateSubscription(t *testing.T) {
 	if err := json.Unmarshal(testFileWanted, &wantedEvents); err != nil {
 		t.Fatal(err)
 	}
-	c1 := uint(61)
-	c2 := uint(62)
-	c3 := uint(63)
-	c4 := uint(64)
+
 	database.AddSubscriptions(10, []models.SubscriptionData{
-		{Coin: &c1, Address: "0x0000000000000000000000000000000000000000", SubscriptionId: 10},
+		{Coin: 61, Address: "0x0000000000000000000000000000000000000000", SubscriptionId: 10},
 	}, context.Background())
 	database.AddSubscriptions(1, []models.SubscriptionData{
-		{Coin: &c2, Address: "0x0000000000000000000000000000000000000000", SubscriptionId: 1},
+		{Coin: 62, Address: "0x0000000000000000000000000000000000000000", SubscriptionId: 1},
 	}, context.Background())
 	database.AddSubscriptions(2, []models.SubscriptionData{
-		{Coin: &c3, Address: "0x0000000000000000000000000000000000000000", SubscriptionId: 2},
+		{Coin: 63, Address: "0x0000000000000000000000000000000000000000", SubscriptionId: 2},
 	}, context.Background())
 	database.AddSubscriptions(3, []models.SubscriptionData{
-		{Coin: &c4, Address: "0x0000000000000000000000000000000000000000", SubscriptionId: 3},
+		{Coin: 64, Address: "0x0000000000000000000000000000000000000000", SubscriptionId: 3},
 	}, context.Background())
 
 	for _, event := range givenEvents {
@@ -126,7 +123,7 @@ func TestSubscriber_UpdateSubscription(t *testing.T) {
 		result, err := database.GetSubscriptionData(wanted.Coin, []string{wanted.Address}, context.Background())
 		assert.Nil(t, err)
 		assert.Equal(t, result[0].SubscriptionId, wanted.Id)
-		assert.Equal(t, wanted.Coin, *result[0].Coin)
+		assert.Equal(t, result[0].Coin, wanted.Coin)
 		assert.Equal(t, result[0].Address, wanted.Address)
 
 	}
diff --git a/tests/integration/setup/testdata/coins.go b/tests/integration/setup/testdata/coins.go
deleted file mode 100644
index 610fd16..0000000
--- a/tests/integration/setup/testdata/coins.go
+++ /dev/null
@@ -1,9 +0,0 @@
-package testdata
-
-import "github.com/trustwallet/blockatlas/coin"
-
-var (
-	EthCoin = coin.Ethereum()
-	BnbCoin = coin.Binance()
-	XrpCoin = coin.Ripple()
-)