Files
sdk/contract/allocations_test.go
zeekayandHanzo Dev da299df77d the corporate name is Lux Industries Inc
Lux Partners Limited is not the entity behind this work. Every place the
old name stood — copyright lines, site footers, brand config, legal and
compliance text — now names the company that actually holds it.

lux.fund is the exception and is not renamed to match: that site belongs
to Lux Assets Management LLC, a different company, and it says so.

Two kinds of line were left for a person rather than rewritten. A dated
news item recording that Lux Partners Limited was established in the Isle
of Man is a historical fact, and renaming it would falsify the record. And
a sentence asserting that the company is domiciled in the Isle of Man is a
claim about a jurisdiction, not a name — an Inc or an LLC is not an Isle
of Man company, so swapping the name there would assert something untrue.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-28 13:05:15 -07:00

195 lines
7.1 KiB
Go

// Copyright (C) 2025, Lux Industries Inc All rights reserved.
// See the file LICENSE for licensing terms.
package contract
import (
"testing"
"github.com/luxfi/crypto"
"github.com/stretchr/testify/require"
)
func TestContractAddressIsInGenesisData(t *testing.T) {
require := require.New(t)
type test struct {
desc string
genesisData []byte
contractAddress crypto.Address
expected bool
shouldErr bool
}
tests := []test{
{
desc: "nil data",
genesisData: nil,
contractAddress: crypto.Address{},
expected: false,
shouldErr: true,
},
{
desc: "not json",
genesisData: []byte("not json"),
contractAddress: crypto.Address{},
expected: false,
shouldErr: true,
},
{
desc: "not evm",
genesisData: []byte("{}"),
contractAddress: crypto.Address{},
expected: false,
shouldErr: true,
},
{
desc: "no allocs",
genesisData: []byte(`
{
"config": {
"byzantiumBlock": 0, "chainId": 1, "constantinopleBlock": 0, "eip150Block": 0,
"eip155Block": 0, "eip158Block": 0,
"feeConfig": {
"gasLimit": "0xb71b00", "targetBlockRate": 2, "minBaseFee": 25000000000,
"targetGas": 60000000, "baseFeeChangeDenominator": 36, "minBlockGasCost": 0,
"maxBlockGasCost": 1000000, "blockGasCostStep": 200000
},
"homesteadBlock": 0, "istanbulBlock": 0, "muirGlacierBlock": 0, "petersburgBlock": 0,
"warpConfig": {
"blockTimestamp": 1727309619, "quorumNumerator": 67
}
},
"nonce": "0x0", "timestamp": 1727309619, "extraData": "0x", "gasLimit": "0xb71b00", "difficulty": "0x0",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"airdropHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"airdropAmount": null, "number": "0x0", "gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"baseFeePerGas": null, "excessBlobGas": null, "blobGasUsed": null,
"alloc": {}
}
`),
contractAddress: crypto.Address{},
expected: false,
shouldErr: false,
},
{
desc: "good path",
genesisData: []byte(`
{
"config": {
"byzantiumBlock": 0, "chainId": 1, "constantinopleBlock": 0, "eip150Block": 0,
"eip155Block": 0, "eip158Block": 0,
"feeConfig": {
"gasLimit": "0xb71b00", "targetBlockRate": 2, "minBaseFee": 25000000000,
"targetGas": 60000000, "baseFeeChangeDenominator": 36, "minBlockGasCost": 0,
"maxBlockGasCost": 1000000, "blockGasCostStep": 200000
},
"homesteadBlock": 0, "istanbulBlock": 0, "muirGlacierBlock": 0, "petersburgBlock": 0,
"warpConfig": {
"blockTimestamp": 1727309619, "quorumNumerator": 67
}
},
"nonce": "0x0", "timestamp": 1727309619, "extraData": "0x", "gasLimit": "0xb71b00", "difficulty": "0x0",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"airdropHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"airdropAmount": null, "number": "0x0", "gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"baseFeePerGas": null, "excessBlobGas": null, "blobGasUsed": null,
"alloc": {
"253b2784c75e510dd0ff1da844684a1ac0aa5fcf": {
"code": "0xfe",
"balance": "0x2086ac351052600000"
}
}
}
`),
contractAddress: crypto.HexToAddress("0x253b2784c75e510dd0ff1da844684a1ac0aa5fcf"),
expected: true,
shouldErr: false,
},
{
desc: "no code",
genesisData: []byte(`
{
"config": {
"byzantiumBlock": 0, "chainId": 1, "constantinopleBlock": 0, "eip150Block": 0,
"eip155Block": 0, "eip158Block": 0,
"feeConfig": {
"gasLimit": "0xb71b00", "targetBlockRate": 2, "minBaseFee": 25000000000,
"targetGas": 60000000, "baseFeeChangeDenominator": 36, "minBlockGasCost": 0,
"maxBlockGasCost": 1000000, "blockGasCostStep": 200000
},
"homesteadBlock": 0, "istanbulBlock": 0, "muirGlacierBlock": 0, "petersburgBlock": 0,
"warpConfig": {
"blockTimestamp": 1727309619, "quorumNumerator": 67
}
},
"nonce": "0x0", "timestamp": 1727309619, "extraData": "0x", "gasLimit": "0xb71b00", "difficulty": "0x0",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"airdropHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"airdropAmount": null, "number": "0x0", "gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"baseFeePerGas": null, "excessBlobGas": null, "blobGasUsed": null,
"alloc": {
"253b2784c75e510dd0ff1da844684a1ac0aa5fcf": {
"balance": "0x2086ac351052600000"
}
}
}
`),
contractAddress: crypto.HexToAddress("0x253b2784c75e510dd0ff1da844684a1ac0aa5fcf"),
expected: false,
shouldErr: false,
},
{
desc: "diff addr",
genesisData: []byte(`
{
"config": {
"byzantiumBlock": 0, "chainId": 1, "constantinopleBlock": 0, "eip150Block": 0,
"eip155Block": 0, "eip158Block": 0,
"feeConfig": {
"gasLimit": "0xb71b00", "targetBlockRate": 2, "minBaseFee": 25000000000,
"targetGas": 60000000, "baseFeeChangeDenominator": 36, "minBlockGasCost": 0,
"maxBlockGasCost": 1000000, "blockGasCostStep": 200000
},
"homesteadBlock": 0, "istanbulBlock": 0, "muirGlacierBlock": 0, "petersburgBlock": 0,
"warpConfig": {
"blockTimestamp": 1727309619, "quorumNumerator": 67
}
},
"nonce": "0x0", "timestamp": 1727309619, "extraData": "0x", "gasLimit": "0xb71b00", "difficulty": "0x0",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"airdropHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"airdropAmount": null, "number": "0x0", "gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"baseFeePerGas": null, "excessBlobGas": null, "blobGasUsed": null,
"alloc": {
"253b2784c75e510dd0ff1da844684a1ac0aa5fcf": {
"code": "0xfe",
"balance": "0x2086ac351052600000"
}
}
}
`),
contractAddress: crypto.HexToAddress("0x253b2724c75e510dd0ff1da844684a1ac0aa5fcc"),
expected: false,
shouldErr: false,
},
}
for _, t := range tests {
b, err := ContractAddressIsInGenesisData(t.genesisData, t.contractAddress)
if t.shouldErr {
require.Error(err, t.desc)
} else {
require.NoError(err, t.desc)
}
require.Equal(t.expected, b, t.desc)
}
}