fix pump wrapper buy and sell

This commit is contained in:
thloyi
2026-05-13 17:30:06 +08:00
parent 10885d5e08
commit 39bfeb085f
2 changed files with 114 additions and 4 deletions

View File

@@ -45,6 +45,10 @@ func TestTxBinaryRoundTrip(t *testing.T) {
MevAgent: MevAgentZan,
MevAgentFee: decimal.RequireFromString("0.040000000"),
},
MevAgentTunneling: {
MevAgent: MevAgentTunneling,
MevAgentFee: decimal.RequireFromString("0.050000000"),
},
},
Swaps: []Swap{
{
@@ -153,6 +157,9 @@ func TestTxBinaryRoundTrip(t *testing.T) {
if !decoded.MevAgent[MevAgentZan].MevAgentFee.Equal(original.MevAgent[MevAgentZan].MevAgentFee) {
t.Fatalf("Zan MevAgent fee mismatch")
}
if !decoded.MevAgent[MevAgentTunneling].MevAgentFee.Equal(original.MevAgent[MevAgentTunneling].MevAgentFee) {
t.Fatalf("Tunneling MevAgent fee mismatch")
}
if len(decoded.Swaps) != 1 {
t.Fatalf("Swaps len = %d, want 1", len(decoded.Swaps))
}
@@ -232,6 +239,87 @@ func TestTxBinaryRejectsUnknownProgramEnum(t *testing.T) {
}
}
func TestTxBinaryLabelEnumsFallbackToUnknown(t *testing.T) {
original := &Tx{
Signer: solana.WrappedSol,
Platform: map[string]platformInfo{
"future-platform": {
Platform: "future-platform",
PlatformFee: decimal.RequireFromString("0.010000000"),
},
},
MevAgent: map[string]mevInfo{
"future-mev-agent": {
MevAgent: "future-mev-agent",
MevAgentFee: decimal.RequireFromString("0.020000000"),
},
},
}
encoded, err := EncodeTxBinary(original)
if err != nil {
t.Fatalf("EncodeTxBinary() error = %v", err)
}
decoded, err := DecodeTxBinary(encoded)
if err != nil {
t.Fatalf("DecodeTxBinary() error = %v", err)
}
if len(decoded.Platform) != 1 {
t.Fatalf("Platform len = %d, want 1", len(decoded.Platform))
}
if _, exists := decoded.Platform["future-platform"]; exists {
t.Fatalf("future platform was preserved, want fallback")
}
if !decoded.Platform[PlatformNone].PlatformFee.Equal(original.Platform["future-platform"].PlatformFee) {
t.Fatalf("PlatformNone fee = %s, want %s", decoded.Platform[PlatformNone].PlatformFee, original.Platform["future-platform"].PlatformFee)
}
if len(decoded.MevAgent) != 1 {
t.Fatalf("MevAgent len = %d, want 1", len(decoded.MevAgent))
}
if _, exists := decoded.MevAgent["future-mev-agent"]; exists {
t.Fatalf("future mev agent was preserved, want fallback")
}
if !decoded.MevAgent[MevAgentUnknown].MevAgentFee.Equal(original.MevAgent["future-mev-agent"].MevAgentFee) {
t.Fatalf("MevAgentUnknown fee = %s, want %s", decoded.MevAgent[MevAgentUnknown].MevAgentFee, original.MevAgent["future-mev-agent"].MevAgentFee)
}
}
func TestTxBinaryReadLabelEnumUnknownIDsFallback(t *testing.T) {
enumTable := txBinaryEnumTables[txBinaryEnumVersionV1]
platformFee := uint64(123)
platformEnc := txBinaryEncoder{}
platformEnc.writeUint32(1)
platformEnc.writeUint16(uint16(len(enumTable.platforms.values) + 10))
platformEnc.writeUint64(platformFee)
platformDec := txBinaryDecoder{reader: bytes.NewReader(platformEnc.bytes())}
platforms, err := txBinaryReadPlatformEntries(&platformDec, enumTable)
if err != nil {
t.Fatalf("txBinaryReadPlatformEntries() error = %v", err)
}
if len(platforms) != 1 || platforms[0].Platform != PlatformNone || platforms[0].PlatformFee != platformFee {
t.Fatalf("platform fallback = %+v, want %s/%d", platforms, PlatformNone, platformFee)
}
mevFee := uint64(456)
mevEnc := txBinaryEncoder{}
mevEnc.writeUint32(1)
mevEnc.writeUint16(uint16(len(enumTable.mevAgents.values) + 10))
mevEnc.writeUint64(mevFee)
mevDec := txBinaryDecoder{reader: bytes.NewReader(mevEnc.bytes())}
mevAgents, err := txBinaryReadMevAgentEntries(&mevDec, enumTable)
if err != nil {
t.Fatalf("txBinaryReadMevAgentEntries() error = %v", err)
}
if len(mevAgents) != 1 || mevAgents[0].MevAgent != MevAgentUnknown || mevAgents[0].MevAgentFee != mevFee {
t.Fatalf("mev agent fallback = %+v, want %s/%d", mevAgents, MevAgentUnknown, mevFee)
}
}
func TestTxBinaryAcceptsKnownEventEnums(t *testing.T) {
events := []string{
TxEventAddLP,