Skip to content

Commit

Permalink
test: multiple accounts state import/export
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanchriswhite committed Jan 27, 2025
1 parent e35ca54 commit 12a072c
Showing 1 changed file with 138 additions and 53 deletions.
191 changes: 138 additions & 53 deletions cmd/poktrolld/cmd/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@ import (
"github.com/stretchr/testify/require"
)

type morseStateInputLocals struct {
Address1Hex,
Address2Hex,
PublicKey1Hex,
PublicKey2Hex string
Account1Amount,
Account2Amount,
App1StakeAmount,
App2StakeAmount,
Supplier1StakeAmount,
Supplier2StakeAmount uint64
}

type morseStateOutputLocals struct {
Address1Hex,
Address2Hex,
PublicKey1Hex,
PublicKey2Hex string
Account1Amount,
Account2Amount uint64
}

var (
mockMorseStateJSONTmpl = template.Must(template.New("morse_state_export").Parse(`
{
Expand All @@ -35,15 +57,27 @@ var (
},
"applications": [
{
"address": "{{.AddressHex}}",
"public_key": "{{.PublicKeyHex}}",
"address": "{{.Address1Hex}}",
"public_key": "{{.PublicKey1Hex}}",
"jailed": false,
"chains": [
"0001"
],
"max_relays": "10000000000000",
"status": 2,
"staked_tokens": "{{.AppStakeAmount}}",
"staked_tokens": "{{.App1StakeAmount}}",
"unstaking_time": "0001-01-01T00:00:00Z"
},
{
"address": "{{.Address2Hex}}",
"public_key": "{{.PublicKey2Hex}}",
"jailed": false,
"chains": [
"0001"
],
"max_relays": "10000000000000",
"status": 2,
"staked_tokens": "{{.App2StakeAmount}}",
"unstaking_time": "0001-01-01T00:00:00Z"
}
],
Expand All @@ -54,16 +88,32 @@ var (
{
"type": "posmint/Account",
"value": {
"address": "{{.AddressHex}}",
"address": "{{.Address1Hex}}",
"coins": [
{
"denom": "upokt",
"amount": "{{.Account1Amount}}"
}
],
"public_key": {
"type": "crypto/ed25519_public_key",
"value": "{{.PublicKey1Hex}}"
}
}
},
{
"type": "posmint/Account",
"value": {
"address": "{{.Address2Hex}}",
"coins": [
{
"denom": "upokt",
"amount": "{{.AccountAmount}}"
"amount": "{{.Account2Amount}}"
}
],
"public_key": {
"type": "crypto/ed25519_public_key",
"value": "{{.PublicKeyHex}}"
"value": "{{.PublicKey2Hex}}"
}
}
}
Expand All @@ -73,15 +123,29 @@ var (
"pos": {
"validators": [
{
"address": "934066aae79da1e8012bacf4953985dc6bac3371",
"public_key": "{{.PublicKeyHex}}",
"address": "{{.Address1Hex}}",
"public_key": "{{.PublicKey1Hex}}",
"jailed": false,
"status": 2,
"chains": [
"0001"
],
"service_url": "http://127.0.0.1:8081",
"tokens": "{{.Supplier1StakeAmount}}",
"unstaking_time": "0001-01-01T00:00:00Z",
"output_address": "",
"reward_delegators": null
},
{
"address": "{{.Address2Hex}}",
"public_key": "{{.PublicKey2Hex}}",
"jailed": false,
"status": 2,
"chains": [
"0001"
],
"service_url": "http://127.0.0.1:8081",
"tokens": "{{.SupplierStakeAmount}}",
"tokens": "{{.Supplier2StakeAmount}}",
"unstaking_time": "0001-01-01T00:00:00Z",
"output_address": "",
"reward_delegators": null
Expand All @@ -91,12 +155,69 @@ var (
}
}
`))
expectedJSONTmpl = template.Must(template.New("expected").Parse(`{
"accounts": {
"{{.Address1Hex}}": {
"address": "{{.Address1Hex}}",
"public_key": {
"type": "crypto/ed25519_public_key",
"value": "{{.PublicKey1Hex}}"
},
"coins": [
{
"denom": "upokt",
"amount": "{{.Account1Amount}}"
}
]
},
"{{.Address2Hex}}": {
"address": "{{.Address2Hex}}",
"public_key": {
"type": "crypto/ed25519_public_key",
"value": "{{.PublicKey2Hex}}"
},
"coins": [
{
"denom": "upokt",
"amount": "{{.Account2Amount}}"
}
]
}
}
}`))

Account1Amount = uint64(2000000)
Account2Amount = uint64(2000020)
App1StakeAmount = uint64(10000000000000)
App2StakeAmount = uint64(10000000000001)
Supplier1StakeAmount = uint64(30000000)
Supplier2StakeAmount = uint64(30000300)
Address1Hex = "934066AAE79DA1E8012BACF4953985DC6BAC3371"
Address2Hex = "3145CF09E0E780A16E57DE7DB2A419CFEA45C830"
PublicKey1Hex = "f68e32d72e7f5f1c797bcd41d8d0e9a1004354c6b1c85429f2ebd7d82ccf4a70"
PublicKey2Hex = "0a825f4415213910f949b9081ee43cca105eae13ca44bb69e93aaad122f52c11"

morseInputLocals = morseStateInputLocals{
Address1Hex: Address1Hex,
Address2Hex: Address2Hex,
PublicKey1Hex: PublicKey1Hex,
PublicKey2Hex: PublicKey2Hex,
Account1Amount: Account1Amount,
Account2Amount: Account2Amount,
App1StakeAmount: App1StakeAmount,
App2StakeAmount: App2StakeAmount,
Supplier1StakeAmount: Supplier1StakeAmount,
Supplier2StakeAmount: Supplier2StakeAmount,
}

AccountAmount = uint64(2000000)
AppStakeAmount = uint64(10000000000000)
SupplierStakeAmount = uint64(30000000)
AddressHex = "934066AAE79DA1E8012BACF4953985DC6BAC3371"
PublicKeyHex = "f68e32d72e7f5f1c797bcd41d8d0e9a1004354c6b1c85429f2ebd7d82ccf4a70"
morseOutputLocals = morseStateOutputLocals{
Address1Hex: Address1Hex,
Address2Hex: Address2Hex,
PublicKey1Hex: PublicKey1Hex,
PublicKey2Hex: PublicKey2Hex,
Account1Amount: App1StakeAmount + Account1Amount + Supplier1StakeAmount,
Account2Amount: App2StakeAmount + Account2Amount + Supplier2StakeAmount,
}
)

func TestCollectMorseAccounts(t *testing.T) {
Expand All @@ -105,19 +226,7 @@ func TestCollectMorseAccounts(t *testing.T) {
inputFile, err := os.CreateTemp(tmpDir, "morse-state-input.json")
require.NoError(t, err)

err = mockMorseStateJSONTmpl.Execute(inputFile, struct {
AccountAmount,
AppStakeAmount,
SupplierStakeAmount uint64
AddressHex,
PublicKeyHex string
}{
AccountAmount,
AppStakeAmount,
SupplierStakeAmount,
AddressHex,
PublicKeyHex,
})
err = mockMorseStateJSONTmpl.Execute(inputFile, morseInputLocals)
require.NoError(t, err)

err = inputFile.Close()
Expand All @@ -131,32 +240,8 @@ func TestCollectMorseAccounts(t *testing.T) {
require.NoError(t, err)

expectedJSONBuf := new(bytes.Buffer)
expectedAmount := AppStakeAmount + AccountAmount + SupplierStakeAmount
err = template.Must(template.New("expected").Parse(`{
"accounts": {
"{{.AddressHex}}": {
"address": "{{.AddressHex}}",
"public_key": {
"type": "crypto/ed25519_public_key",
"value": "{{.PublicKeyHex}}"
},
"coins": [
{
"denom": "upokt",
"amount": "{{.AccountAmount}}"
}
]
}
}
}`)).Execute(expectedJSONBuf, struct {
AddressHex,
PublicKeyHex string
AccountAmount uint64
}{
AddressHex,
PublicKeyHex,
expectedAmount,
})
err = expectedJSONTmpl.Execute(expectedJSONBuf, morseOutputLocals)
require.NoError(t, err)

// Strip all whitespace from the expected JSON.
expectedJSON := expectedJSONBuf.String()
Expand Down

0 comments on commit 12a072c

Please sign in to comment.