mirror of
https://github.com/status-im/status-go.git
synced 2026-08-31 00:51:12 +00:00
Part of the Go project layout migration, item 27. Pure move plus import-path rewrite across 502 files. No API or behaviour change. `internal/` keeps the messaging application logic unimportable from outside the module, which is what the issue asks for -- status-go is consumed through the C-bindings in mobile/, not as a Go library. Things that had to follow the move, beyond the Go imports: - tools/generate-handlers/template.txt. messenger_handlers.go is generated, and the template hard-codes the imports it emits, so the generated file kept importing protocol/common and failed typecheck. - .gitignore. The ignore rule for that generated file was pinned to the old path; without moving it, a 1486-line generated file starts being tracked. - Makefile: the logosstorage and torrent test targets (both the archive packages and ./protocol itself), the archive README, migration-protocol. - scripts/run_unit_tests.sh, which names the protocol package explicitly to shard its tests. - scripts/cleanup_generated_files.sh and .golangci.yml. scripts/migration_check.sh also needed a fix that is not specific to this move: it validated every file the branch touched under a migration dir against the timestamp naming rule, and a directory rename makes every migration in it look newly added. It now excludes renames, so moving a migration is not mistaken for adding one. refs #7067
90 lines
2.6 KiB
Go
90 lines
2.6 KiB
Go
package ens
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/status-im/status-go/internal/db/appdatabase"
|
|
"github.com/status-im/status-go/internal/protocol/sqlite"
|
|
"github.com/status-im/status-go/internal/testutils"
|
|
)
|
|
|
|
func TestGetENSToBeVerified(t *testing.T) {
|
|
pk := "1"
|
|
name := "test.eth"
|
|
updatedName := "test2.eth"
|
|
|
|
db, err := testutils.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
|
|
require.NoError(t, err)
|
|
err = sqlite.Migrate(db)
|
|
require.NoError(t, err)
|
|
|
|
persistence := NewPersistence(db)
|
|
require.NotNil(t, persistence)
|
|
|
|
record := VerificationRecord{Name: name, PublicKey: pk, Clock: 2}
|
|
|
|
// We add a record, it should be nil
|
|
response, err := persistence.AddRecord(record)
|
|
require.NoError(t, err)
|
|
require.Nil(t, response)
|
|
|
|
// We add a record again, it should return the same record
|
|
response, err = persistence.AddRecord(record)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, response)
|
|
|
|
require.False(t, response.Verified)
|
|
require.Equal(t, record.Name, response.Name)
|
|
require.Equal(t, record.PublicKey, response.PublicKey)
|
|
|
|
// We add a record again, with a different clock value
|
|
record.Clock++
|
|
response, err = persistence.AddRecord(record)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, response)
|
|
|
|
require.False(t, response.Verified)
|
|
require.Equal(t, record.Name, response.Name)
|
|
require.Equal(t, record.PublicKey, response.PublicKey)
|
|
|
|
// We add a record again, with a different name, but lower clock value
|
|
record.Clock--
|
|
record.Name = updatedName
|
|
response, err = persistence.AddRecord(record)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, response)
|
|
|
|
require.False(t, response.Verified)
|
|
require.Equal(t, name, response.Name)
|
|
require.Equal(t, record.PublicKey, response.PublicKey)
|
|
|
|
// We add a record again, with a different name and higher clock value
|
|
record.Clock += 2
|
|
record.Name = updatedName
|
|
response, err = persistence.AddRecord(record)
|
|
require.NoError(t, err)
|
|
require.Nil(t, response)
|
|
|
|
// update the record
|
|
|
|
record.Verified = false
|
|
record.VerificationRetries = 10
|
|
record.NextRetry = 20
|
|
record.VerifiedAt = 30
|
|
|
|
err = persistence.UpdateRecords([]*VerificationRecord{&record})
|
|
require.NoError(t, err)
|
|
|
|
toBeVerified, err := persistence.GetENSToBeVerified(20)
|
|
require.NoError(t, err)
|
|
require.Len(t, toBeVerified, 1)
|
|
require.False(t, toBeVerified[0].Verified)
|
|
require.Equal(t, uint64(10), toBeVerified[0].VerificationRetries)
|
|
require.Equal(t, uint64(20), toBeVerified[0].NextRetry)
|
|
require.Equal(t, uint64(30), toBeVerified[0].VerifiedAt)
|
|
require.Equal(t, updatedName, toBeVerified[0].Name)
|
|
require.Equal(t, pk, toBeVerified[0].PublicKey)
|
|
}
|