Skip to content

Commit

Permalink
PRO-1653 add manuf token id col, change pkey, update fkeys (#163)
Browse files Browse the repository at this point in the history
* add manuf token id col, change pkey, update fkeys

* fixed compilation, couple test failures

* minor name change

* fix test
  • Loading branch information
JamesReate authored Jul 20, 2023
1 parent 5cb5aaf commit 8c7e135
Show file tree
Hide file tree
Showing 21 changed files with 165 additions and 604 deletions.
2 changes: 1 addition & 1 deletion cmd/devices-api/remake_aftermarket_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func remakeAftermarketTopic(ctx context.Context, pdb db.Store, producer sarama.S

if err := reg.Register2(&services.AftermarketDeviceVehicleMapping{
AftermarketDevice: services.AftermarketDeviceVehicleMappingAftermarketDevice{
Address: common.BytesToAddress(amd.EthereumAddress.Bytes),
Address: common.BytesToAddress(amd.EthereumAddress),
Token: amd.TokenID.Int(nil),
Serial: amd.Serial,
IntegrationID: integ.Id,
Expand Down
4 changes: 2 additions & 2 deletions internal/controllers/nft_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ func (nc *NFTController) GetAftermarketDeviceNFTMetadata(c *fiber.Ctx) error {
return err
}
var name string
if three, err := mnemonic.EntropyToMnemonicThreeWords(unit.EthereumAddress.Bytes); err == nil {
if three, err := mnemonic.EntropyToMnemonicThreeWords(unit.EthereumAddress); err == nil {
name = strings.Join(three, " ")
}

Expand All @@ -395,7 +395,7 @@ func (nc *NFTController) GetAftermarketDeviceNFTMetadata(c *fiber.Ctx) error {
Description: name + ", a DIMO hardware device.",
Image: fmt.Sprintf("%s/v1/aftermarket/device/%s/image", nc.Settings.DeploymentBaseURL, tid),
Attributes: []NFTAttribute{
{TraitType: "Ethereum Address", Value: common.BytesToAddress(unit.EthereumAddress.Bytes).String()},
{TraitType: "Ethereum Address", Value: common.BytesToAddress(unit.EthereumAddress).String()},
{TraitType: "Serial Number", Value: unit.Serial},
},
})
Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/user_devices_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ func (udc *UserDevicesController) UpdateVIN(c *fiber.Ctx) error {
}

found, err := models.AftermarketDevices(
models.AftermarketDeviceWhere.EthereumAddress.EQ(null.BytesFrom(recAddr.Bytes())),
models.AftermarketDeviceWhere.EthereumAddress.EQ(recAddr.Bytes()),
).Exists(c.Context(), udc.DBS().Reader)
if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions internal/controllers/user_devices_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ func (s *UserDevicesControllerTestSuite) TestGetMyUserDevices() {
integration := test.BuildIntegrationGRPC(constants.AutoPiVendor, 10, 0)
dd := test.BuildDeviceDefinitionGRPC(ksuid.New().String(), "Ford", "F150", 2020, integration)
ud := test.SetupCreateUserDevice(s.T(), s.testUserID, dd[0].DeviceDefinitionId, nil, "", s.pdb)
_ = test.SetupCreateAftermarketDevice(s.T(), testUserID, unitID, func(s string) *string { return &s }(deviceID), s.pdb)
_ = test.SetupCreateAftermarketDevice(s.T(), testUserID, nil, unitID, func(s string) *string { return &s }(deviceID), s.pdb)
_ = test.SetupCreateUserDeviceAPIIntegration(s.T(), unitID, deviceID, ud.ID, integration.Id, s.pdb)

addr := "67B94473D81D0cd00849D563C94d0432Ac988B49"
Expand Down Expand Up @@ -507,7 +507,7 @@ func (s *UserDevicesControllerTestSuite) TestGetMyUserDevicesNoDuplicates() {
integration := test.BuildIntegrationGRPC(constants.AutoPiVendor, 10, 0)
dd := test.BuildDeviceDefinitionGRPC(ksuid.New().String(), "Ford", "F150", 2020, integration)
ud := test.SetupCreateUserDeviceWithDeviceID(s.T(), userID, deviceID, dd[0].DeviceDefinitionId, nil, "", s.pdb)
_ = test.SetupCreateAftermarketDevice(s.T(), userID, unitID, func(s string) *string { return &s }(deviceID), s.pdb)
_ = test.SetupCreateAftermarketDevice(s.T(), userID, nil, unitID, func(s string) *string { return &s }(deviceID), s.pdb)
_ = test.SetupCreateUserDeviceAPIIntegration(s.T(), unitID, deviceID, ud.ID, integration.Id, s.pdb)

addr := "67B94473D81D0cd00849D563C94d0432Ac988B49"
Expand Down Expand Up @@ -650,7 +650,7 @@ func (s *UserDevicesControllerTestSuite) TestNameValidate() {
func (s *UserDevicesControllerTestSuite) TestPatchName() {
ud := test.SetupCreateUserDevice(s.T(), s.testUserID, ksuid.New().String(), nil, "", s.pdb)
deviceID := uuid.New().String()
apunit := test.SetupCreateAftermarketDevice(s.T(), s.testUserID, uuid.NewString(), &deviceID, s.pdb)
apunit := test.SetupCreateAftermarketDevice(s.T(), s.testUserID, nil, uuid.NewString(), &deviceID, s.pdb)
autoPiIntID := ksuid.New().String()
vehicleID := 3214
_ = test.SetupCreateUserDeviceAPIIntegration(s.T(), apunit.Serial, deviceID, ud.ID, autoPiIntID, s.pdb)
Expand Down Expand Up @@ -804,7 +804,7 @@ func (s *UserDevicesControllerTestSuite) TestGetRange() {
ddID := ksuid.New().String()
integration := test.BuildIntegrationGRPC(constants.AutoPiVendor, 10, 0)
smartCarIntegration := test.BuildIntegrationGRPC(constants.SmartCarVendor, 10, 0)
_ = test.SetupCreateAftermarketDevice(s.T(), testUserID, autoPiUnitID, &autoPiDeviceID, s.pdb)
_ = test.SetupCreateAftermarketDevice(s.T(), testUserID, nil, autoPiUnitID, &autoPiDeviceID, s.pdb)

gddir := []*grpc.GetDeviceDefinitionItemResponse{
{
Expand Down
34 changes: 16 additions & 18 deletions internal/controllers/user_integrations_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,10 +483,8 @@ func (udc *UserDevicesController) GetAutoPiUnitInfo(c *fiber.Ctx) error {
tokenID = dbUnit.TokenID.Int(nil)
}

if dbUnit.EthereumAddress.Valid {
addr := common.BytesToAddress(dbUnit.EthereumAddress.Bytes)
ethereumAddress = &addr
}
addr := common.BytesToAddress(dbUnit.EthereumAddress)
ethereumAddress = &addr

if dbUnit.OwnerAddress.Valid {
addr := common.BytesToAddress(dbUnit.OwnerAddress.Bytes)
Expand Down Expand Up @@ -719,15 +717,15 @@ func (udc *UserDevicesController) GetAutoPiPairMessage(c *fiber.Ctx) error {
return opaqueInternalError
}

var autoPiUnit *models.AftermarketDevice
var aftermarketDevice *models.AftermarketDevice

if extID := c.Query("external_id"); extID != "" {
unitID, err := uuid.Parse(extID)
if err != nil {
return err
}

autoPiUnit, err = models.AftermarketDevices(
aftermarketDevice, err = models.AftermarketDevices(
models.AftermarketDeviceWhere.Serial.EQ(unitID.String()),
qm.Load(models.AftermarketDeviceRels.PairRequest),
qm.Load(models.AftermarketDeviceRels.UnpairRequest),
Expand All @@ -753,33 +751,33 @@ func (udc *UserDevicesController) GetAutoPiPairMessage(c *fiber.Ctx) error {
}

// Conflict with web2 pairing?
if autoPiUnit != nil && (!udai.Serial.Valid || udai.Serial.String != autoPiUnit.Serial) {
if aftermarketDevice != nil && (!udai.Serial.Valid || udai.Serial.String != aftermarketDevice.Serial) {
return fiber.NewError(fiber.StatusConflict, "Vehicle already paired with another AutoPi.")
}

autoPiUnit = udai.R.SerialAftermarketDevice
aftermarketDevice = udai.R.SerialAftermarketDevice
}

if autoPiUnit.R.PairRequest != nil && autoPiUnit.R.PairRequest.Status != "Failed" {
if autoPiUnit.R.PairRequest.Status == models.MetaTransactionRequestStatusConfirmed {
if aftermarketDevice.R.PairRequest != nil && aftermarketDevice.R.PairRequest.Status != "Failed" {
if aftermarketDevice.R.PairRequest.Status == models.MetaTransactionRequestStatusConfirmed {
return fiber.NewError(fiber.StatusConflict, "AutoPi already paired.")
}
return fiber.NewError(fiber.StatusConflict, "AutoPi pairing in process.")
}

if autoPiUnit.TokenID.IsZero() {
if aftermarketDevice.TokenID.IsZero() {
return fiber.NewError(fiber.StatusConflict, "AutoPi not yet minted.")
}

if ud.R.VehicleNFT == nil || ud.R.VehicleNFT.TokenID.IsZero() {
return fiber.NewError(fiber.StatusConflict, "Vehicle not yet minted.")
}

if !autoPiUnit.OwnerAddress.Valid {
if !aftermarketDevice.OwnerAddress.Valid {
return fiber.NewError(fiber.StatusConflict, "Device not yet claimed.")
}

apToken := autoPiUnit.TokenID.Int(nil)
apToken := aftermarketDevice.TokenID.Int(nil)
vehicleToken := ud.R.VehicleNFT.TokenID.Int(nil)

user, err := udc.usersClient.GetUser(c.Context(), &pb.GetUserRequest{Id: userID})
Expand All @@ -793,7 +791,7 @@ func (udc *UserDevicesController) GetAutoPiPairMessage(c *fiber.Ctx) error {
}

if udc.Settings.IsProduction() {
if common.HexToAddress(*user.EthereumAddress) != common.BytesToAddress(autoPiUnit.OwnerAddress.Bytes) {
if common.HexToAddress(*user.EthereumAddress) != common.BytesToAddress(aftermarketDevice.OwnerAddress.Bytes) {
return fiber.NewError(fiber.StatusConflict, "AutoPi claimed by another user.")
}
}
Expand Down Expand Up @@ -988,7 +986,7 @@ func (udc *UserDevicesController) PostPairAutoPi(c *fiber.Ctx) error {

if recAddr, err := helpers.Ecrecover(hash.Bytes(), aftermarketDeviceSig); err != nil {
return err
} else if recAddr != common.BytesToAddress(autoPiUnit.EthereumAddress.Bytes) {
} else if recAddr != common.BytesToAddress(autoPiUnit.EthereumAddress) {
return fiber.NewError(fiber.StatusBadRequest, "Incorrect aftermarket device signature.")
}

Expand Down Expand Up @@ -1351,7 +1349,7 @@ func (udc *UserDevicesController) PostUnclaimAutoPi(c *fiber.Ctx) error {

logger.Info().Msg("Got unclaim request.")

unit, err := models.FindAftermarketDevice(c.Context(), udc.DBS().Reader, unitID)
unit, err := models.AftermarketDevices(models.AftermarketDeviceWhere.Serial.EQ(unitID)).One(c.Context(), udc.DBS().Reader)
if err != nil {
if err == sql.ErrNoRows {
return fiber.NewError(fiber.StatusNotFound, "AutoPi not minted, or unit ID invalid.")
Expand Down Expand Up @@ -1422,7 +1420,7 @@ func (udc *UserDevicesController) PostClaimAutoPi(c *fiber.Ctx) error {
return fiber.NewError(fiber.StatusInternalServerError, "Internal error.")
}

if unit.TokenID.IsZero() || !unit.EthereumAddress.Valid {
if unit.TokenID.IsZero() {
return fiber.NewError(fiber.StatusNotFound, "AutoPi not minted.")
}

Expand Down Expand Up @@ -1497,7 +1495,7 @@ func (udc *UserDevicesController) PostClaimAutoPi(c *fiber.Ctx) error {
return err
}

realAmAddr := common.BytesToAddress(unit.EthereumAddress.Bytes)
realAmAddr := common.BytesToAddress(unit.EthereumAddress)

if recAmAddr != realAmAddr {
return fiber.NewError(fiber.StatusBadRequest, "Aftermarket device signature invalid.")
Expand Down
29 changes: 15 additions & 14 deletions internal/controllers/user_integrations_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ func (s *UserIntegrationsControllerTestSuite) TestPostAutoPiBlockedForDuplicateD
deviceID = "1dd96159-3bb2-9472-91f6-72fe9211cfeb"
unitID = "431d2e89-46f1-6884-6226-5d1ad20c84d9"
)
_ = test.SetupCreateAftermarketDevice(s.T(), testUserID, unitID, func(s string) *string { return &s }(deviceID), s.pdb)
_ = test.SetupCreateAftermarketDevice(s.T(), testUserID, nil, unitID, func(s string) *string { return &s }(deviceID), s.pdb)
test.SetupCreateUserDeviceAPIIntegration(s.T(), unitID, deviceID, ud.ID, integration.Id, s.pdb)

req := fmt.Sprintf(`{
Expand Down Expand Up @@ -564,7 +564,7 @@ func (s *UserIntegrationsControllerTestSuite) TestPostAutoPiBlockedForDuplicateD
deviceID = "1dd96159-3bb2-9472-91f6-72fe9211cfeb"
unitID = "431d2e89-46f1-6884-6226-5d1ad20c84d9"
)
_ = test.SetupCreateAftermarketDevice(s.T(), testUserID, unitID, func(s string) *string { return &s }(deviceID), s.pdb)
_ = test.SetupCreateAftermarketDevice(s.T(), testUserID, nil, unitID, func(s string) *string { return &s }(deviceID), s.pdb)
// test user
ud2 := test.SetupCreateUserDevice(s.T(), testUser2, dd[0].DeviceDefinitionId, nil, "", s.pdb)

Expand Down Expand Up @@ -594,7 +594,7 @@ func (s *UserIntegrationsControllerTestSuite) TestGetAutoPiInfoNoUDAI_ShouldUpda
app.Get("/autopi/unit/:unitID", test.AuthInjectorTestHandler(testUserID), owner.AutoPi(s.pdb, s.userClient, &logger), c.GetAutoPiUnitInfo)
// arrange
const unitID = "431d2e89-46f1-6884-6226-5d1ad20c84d9"
test.SetupCreateAftermarketDevice(s.T(), "", unitID, nil, s.pdb)
test.SetupCreateAftermarketDevice(s.T(), "", nil, unitID, nil, s.pdb)
autopiAPISvc.EXPECT().GetDeviceByUnitID(unitID).Times(1).Return(&services.AutoPiDongleDevice{
IsUpdated: false,
UnitID: unitID,
Expand Down Expand Up @@ -632,7 +632,7 @@ func (s *UserIntegrationsControllerTestSuite) TestGetAutoPiInfoNoUDAI_UpToDate()
app.Get("/autopi/unit/:unitID", test.AuthInjectorTestHandler(testUserID), owner.AutoPi(s.pdb, s.userClient, &logger), c.GetAutoPiUnitInfo)
// arrange
const unitID = "431d2e89-46f1-6884-6226-5d1ad20c84d9"
test.SetupCreateAftermarketDevice(s.T(), "", unitID, nil, s.pdb)
test.SetupCreateAftermarketDevice(s.T(), "", nil, unitID, nil, s.pdb)
autopiAPISvc.EXPECT().GetDeviceByUnitID(unitID).Times(1).Return(&services.AutoPiDongleDevice{
IsUpdated: true,
UnitID: unitID,
Expand Down Expand Up @@ -667,7 +667,7 @@ func (s *UserIntegrationsControllerTestSuite) TestGetAutoPiInfoNoUDAI_FutureUpda
app.Get("/autopi/unit/:unitID", test.AuthInjectorTestHandler(testUserID), owner.AutoPi(s.pdb, s.userClient, &logger), c.GetAutoPiUnitInfo)
// arrange
const unitID = "431d2e89-46f1-6884-6226-5d1ad20c84d9"
test.SetupCreateAftermarketDevice(s.T(), "", unitID, nil, s.pdb)
test.SetupCreateAftermarketDevice(s.T(), "", nil, unitID, nil, s.pdb)
autopiAPISvc.EXPECT().GetDeviceByUnitID(unitID).Times(1).Return(&services.AutoPiDongleDevice{
IsUpdated: false,
UnitID: unitID,
Expand Down Expand Up @@ -703,7 +703,7 @@ func (s *UserIntegrationsControllerTestSuite) TestGetAutoPiInfoNoUDAI_ShouldUpda
app.Get("/autopi/unit/:unitID", test.AuthInjectorTestHandler(testUserID), owner.AutoPi(s.pdb, s.userClient, &logger), c.GetAutoPiUnitInfo)
// arrange
const unitID = "431d2e89-46f1-6884-6226-5d1ad20c84d9"
test.SetupCreateAftermarketDevice(s.T(), "", unitID, nil, s.pdb)
test.SetupCreateAftermarketDevice(s.T(), "", nil, unitID, nil, s.pdb)
autopiAPISvc.EXPECT().GetDeviceByUnitID(unitID).Times(1).Return(&services.AutoPiDongleDevice{
IsUpdated: false,
UnitID: unitID,
Expand Down Expand Up @@ -770,22 +770,23 @@ func (s *UserIntegrationsControllerTestSuite) TestPairAftermarketNoLegacy() {
}
s.Require().NoError(vnft.Insert(s.ctx, s.pdb.DBS().Writer, boil.Infer()))

apUnit := test.SetupCreateAftermarketDevice(s.T(), testUserID, unitID, &deviceID, s.pdb)
apUnit.TokenID = types.NewNullDecimal(decimal.New(5, 0))
apUnit.EthereumAddress = null.BytesFrom(common.BigToAddress(big.NewInt(2)).Bytes())
apUnit.OwnerAddress = null.BytesFrom(userAddr.Bytes())
_, err = apUnit.Update(s.ctx, s.pdb.DBS().Writer, boil.Infer())
s.Require().NoError(err)
aftermarketDevice := test.SetupCreateAftermarketDevice(s.T(), testUserID, common.BigToAddress(big.NewInt(2)).Bytes(), unitID, &deviceID, s.pdb)
aftermarketDevice.TokenID = types.NewNullDecimal(decimal.New(5, 0))
aftermarketDevice.OwnerAddress = null.BytesFrom(userAddr.Bytes())
row, errAMD := aftermarketDevice.Update(s.ctx, s.pdb.DBS().Writer, boil.Infer())
s.Assert().Equal(int64(1), row)
s.Require().NoError(errAMD)

app := fiber.New()
app.Use(test.AuthInjectorTestHandler(userID))
app.Get("/:userDeviceID/pair", c.GetAutoPiPairMessage)
app.Post("/:userDeviceID/pair", c.PostPairAutoPi)

req := test.BuildRequest("GET", "/"+ud.ID+"/pair?external_id="+unitID, "")
req := test.BuildRequest("GET", "/"+ud.ID+"/pair?external_id="+aftermarketDevice.Serial, "")

res, err := app.Test(req)
s.Require().NoError(err)
s.Require().Equal(fiber.StatusOK, res.StatusCode) // todo issue - this is returning 409 instead of 200? due to change in how get unit?
defer res.Body.Close()

var td signer.TypedData
Expand All @@ -799,7 +800,7 @@ func (s *UserIntegrationsControllerTestSuite) TestPairAftermarketNoLegacy() {
userSig[64] += 27

in := map[string]any{
"externalId": apUnit.Serial,
"externalId": aftermarketDevice.Serial,
"signature": hexutil.Bytes(userSig).String(),
}

Expand Down
2 changes: 1 addition & 1 deletion internal/middleware/owner/owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func AutoPi(dbs db.Store, usersClient pb.UserServiceClient, logger *zerolog.Logg
c.Locals("unitID", unitID)
c.Locals("logger", &logger)

autopiUnit, err := models.FindAftermarketDevice(c.Context(), dbs.DBS().Reader, unitID)
autopiUnit, err := models.AftermarketDevices(models.AftermarketDeviceWhere.Serial.EQ(unitID)).One(c.Context(), dbs.DBS().Reader)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return fiber.NewError(fiber.StatusNotFound, "AutoPi not minted, or unit ID invalid.")
Expand Down
4 changes: 2 additions & 2 deletions internal/services/autopi/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func (i *Integration) Pair(ctx context.Context, autoPiTokenID, vehicleTokenID *b

err = i.apReg.Register2(&services.AftermarketDeviceVehicleMapping{
AftermarketDevice: services.AftermarketDeviceVehicleMappingAftermarketDevice{
Address: common.BytesToAddress(autoPiModel.EthereumAddress.Bytes),
Address: common.BytesToAddress(autoPiModel.EthereumAddress),
Token: autoPiTokenID,
Serial: autoPiModel.Serial,
IntegrationID: integ.Id,
Expand Down Expand Up @@ -367,7 +367,7 @@ func (i *Integration) Unpair(ctx context.Context, autoPiTokenID, vehicleTokenID
return err
}

err = i.apReg.Deregister2(common.BytesToAddress(autoPiModel.EthereumAddress.Bytes))
err = i.apReg.Deregister2(common.BytesToAddress(autoPiModel.EthereumAddress))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/services/autopi_api_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (s *AutoPiAPIServiceTestSuite) TestCommandRaw() {
apiURL = "https://mock.town"
jobID = "321"
)
_ = test.SetupCreateAftermarketDevice(s.T(), testUserID, unitID, func(s string) *string { return &s }(deviceID), s.pdb)
_ = test.SetupCreateAftermarketDevice(s.T(), testUserID, nil, unitID, func(s string) *string { return &s }(deviceID), s.pdb)
// http client mock
httpmock.Activate()
defer httpmock.DeactivateAndReset()
Expand Down
2 changes: 1 addition & 1 deletion internal/services/contracts_events_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func (c *ContractsEventsConsumer) setMintedAfterMarketDevice(e *ContractEventDat

amd := models.AftermarketDevice{
Serial: device.UnitID,
EthereumAddress: null.BytesFrom(args.AftermarketDeviceAddress.Bytes()),
EthereumAddress: args.AftermarketDeviceAddress.Bytes(),
TokenID: types.NewNullDecimal(new(decimal.Big).SetBigMantScale(args.TokenId, 0)),
}
_ = amd.Metadata.Marshal(amdMd)
Expand Down
3 changes: 1 addition & 2 deletions internal/services/fingerprint/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/rs/zerolog"
"github.com/volatiletech/null/v8"
"github.com/volatiletech/sqlboiler/v4/queries/qm"
)

Expand Down Expand Up @@ -107,7 +106,7 @@ func (c *Consumer) Handle(ctx context.Context, event *Event) error {
}

ad, err := models.AftermarketDevices(
models.AftermarketDeviceWhere.EthereumAddress.EQ(null.BytesFrom(addr.Bytes())),
models.AftermarketDeviceWhere.EthereumAddress.EQ(addr.Bytes()),
qm.Load(qm.Rels(models.AftermarketDeviceRels.VehicleToken, models.VehicleNFTRels.Claim)),
).One(ctx, c.DBS.DBS().Reader)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/services/fingerprint/consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (s *ConsumerTestSuite) TestVinCredentialerHandler() {
TokenID: types.NewNullDecimal(new(decimal.Big).SetBigMantScale(big.NewInt(13), 0)),
VehicleTokenID: types.NewNullDecimal(new(decimal.Big).SetBigMantScale(tokenID, 0)),
Beneficiary: null.BytesFrom(common.BytesToAddress([]byte{uint8(1)}).Bytes()),
EthereumAddress: ownerAddress,
EthereumAddress: ownerAddress.Bytes,
}

userDevice := models.UserDevice{
Expand Down Expand Up @@ -203,7 +203,7 @@ func (s *ConsumerTestSuite) TestVinCredentialerHandler() {
UpdatedAt: time.Now(),
TokenID: types.NewNullDecimal(new(decimal.Big).SetBigMantScale(big.NewInt(13), 0)),
Beneficiary: null.BytesFrom(common.BytesToAddress([]byte{uint8(1)}).Bytes()),
EthereumAddress: ownerAddress,
EthereumAddress: ownerAddress.Bytes,
},
},
}
Expand Down
9 changes: 5 additions & 4 deletions internal/test/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,11 @@ func SetupCreateUserDeviceWithDeviceID(t *testing.T, testUserID string, deviceID
return ud
}

func SetupCreateAftermarketDevice(t *testing.T, userID, unitID string, deviceID *string, pdb db.Store) *models.AftermarketDevice {
func SetupCreateAftermarketDevice(t *testing.T, userID string, bytes []byte, unitID string, deviceID *string, pdb db.Store) *models.AftermarketDevice {
amd := models.AftermarketDevice{
Serial: unitID,
UserID: null.StringFrom(userID),
EthereumAddress: bytes, // pkey
Serial: unitID,
UserID: null.StringFrom(userID),
}
if deviceID != nil {
amdMD := map[string]any{"autoPiDeviceId": *deviceID}
Expand All @@ -264,7 +265,7 @@ func SetupCreateMintedAftermarketDevice(t *testing.T, userID, unitID string, tok
Serial: unitID,
UserID: null.StringFrom(userID),
TokenID: types.NewNullDecimal(new(decimal.Big).SetBigMantScale(tokenID, 0)),
EthereumAddress: null.BytesFrom(addr.Bytes()),
EthereumAddress: addr.Bytes(),
}
if deviceID != nil {
amdMD := map[string]any{"autoPiDeviceId": *deviceID}
Expand Down
Loading

0 comments on commit 8c7e135

Please sign in to comment.