Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 8 additions & 21 deletions ledger/allegra/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,6 @@ func TestUtxoValidateValueNotConservedUtxo(t *testing.T) {
var testInputAmount uint64 = 555666777
var testFee uint64 = 123456
var testStakeDeposit uint64 = 2_000_000
var testStakeCred1 = []byte{0x01, 0x23, 0x45}
var testStakeCred2 = []byte{0xab, 0xcd, 0xef}
testOutputExactAmount := testInputAmount - testFee
testOutputUnderAmount := testOutputExactAmount - 999
testOutputOverAmount := testOutputExactAmount + 999
Expand Down Expand Up @@ -535,13 +533,6 @@ func TestUtxoValidateValueNotConservedUtxo(t *testing.T) {
},
},
},
MockStakeRegistration: []common.StakeRegistrationCertificate{
{
StakeRegistration: common.StakeCredential{
Credential: testStakeCred2,
},
},
},
}
testSlot := uint64(0)
testProtocolParams := &allegra.AllegraProtocolParameters{
Expand All @@ -568,18 +559,16 @@ func TestUtxoValidateValueNotConservedUtxo(t *testing.T) {
}
},
)
// First stake registration
// Stake registration
t.Run(
"first stake registration",
"stake registration",
func(t *testing.T) {
testTx.Body.TxOutputs[0].OutputAmount = testOutputExactAmount - testStakeDeposit
testTx.Body.TxCertificates = []common.CertificateWrapper{
{
Type: common.CertificateTypeStakeRegistration,
Certificate: &common.StakeRegistrationCertificate{
StakeRegistration: common.StakeCredential{
Credential: testStakeCred1,
},
StakeRegistration: common.StakeCredential{},
},
},
}
Expand All @@ -597,18 +586,16 @@ func TestUtxoValidateValueNotConservedUtxo(t *testing.T) {
}
},
)
// Second stake registration
// Stake deregistration
t.Run(
"second stake registration",
"stake deregistration",
func(t *testing.T) {
testTx.Body.TxOutputs[0].OutputAmount = testOutputExactAmount
testTx.Body.TxOutputs[0].OutputAmount = testOutputExactAmount + testStakeDeposit
testTx.Body.TxCertificates = []common.CertificateWrapper{
{
Type: common.CertificateTypeStakeRegistration,
Certificate: &common.StakeRegistrationCertificate{
StakeRegistration: common.StakeCredential{
Credential: testStakeCred2,
},
Certificate: &common.StakeDeregistrationCertificate{
StakeDeregistration: common.StakeCredential{},
},
},
}
Expand Down
29 changes: 8 additions & 21 deletions ledger/alonzo/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,6 @@ func TestUtxoValidateValueNotConservedUtxo(t *testing.T) {
var testInputAmount uint64 = 555666777
var testFee uint64 = 123456
var testStakeDeposit uint64 = 2_000_000
var testStakeCred1 = []byte{0x01, 0x23, 0x45}
var testStakeCred2 = []byte{0xab, 0xcd, 0xef}
testOutputExactAmount := testInputAmount - testFee
testOutputUnderAmount := testOutputExactAmount - 999
testOutputOverAmount := testOutputExactAmount + 999
Expand Down Expand Up @@ -554,13 +552,6 @@ func TestUtxoValidateValueNotConservedUtxo(t *testing.T) {
},
},
},
MockStakeRegistration: []common.StakeRegistrationCertificate{
{
StakeRegistration: common.StakeCredential{
Credential: testStakeCred2,
},
},
},
}
testSlot := uint64(0)
testProtocolParams := &alonzo.AlonzoProtocolParameters{
Expand Down Expand Up @@ -591,18 +582,16 @@ func TestUtxoValidateValueNotConservedUtxo(t *testing.T) {
}
},
)
// First stake registration
// Stake registration
t.Run(
"first stake registration",
"stake registration",
func(t *testing.T) {
testTx.Body.TxOutputs[0].OutputAmount.Amount = testOutputExactAmount - testStakeDeposit
testTx.Body.TxCertificates = []common.CertificateWrapper{
{
Type: common.CertificateTypeStakeRegistration,
Certificate: &common.StakeRegistrationCertificate{
StakeRegistration: common.StakeCredential{
Credential: testStakeCred1,
},
StakeRegistration: common.StakeCredential{},
},
},
}
Expand All @@ -620,18 +609,16 @@ func TestUtxoValidateValueNotConservedUtxo(t *testing.T) {
}
},
)
// Second stake registration
// Stake deregistration
t.Run(
"second stake registration",
"stake deregistration",
func(t *testing.T) {
testTx.Body.TxOutputs[0].OutputAmount.Amount = testOutputExactAmount
testTx.Body.TxOutputs[0].OutputAmount.Amount = testOutputExactAmount + testStakeDeposit
testTx.Body.TxCertificates = []common.CertificateWrapper{
{
Type: common.CertificateTypeStakeRegistration,
Certificate: &common.StakeRegistrationCertificate{
StakeRegistration: common.StakeCredential{
Credential: testStakeCred2,
},
Certificate: &common.StakeDeregistrationCertificate{
StakeDeregistration: common.StakeCredential{},
},
},
}
Expand Down
16 changes: 8 additions & 8 deletions ledger/babbage/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func UtxoValidateValueNotConservedUtxo(tx common.Transaction, slot uint64, ls co
return errors.New("pparams are not expected type")
}
// Calculate consumed value
// consumed = value from input(s) + withdrawals + refunds(?)
// consumed = value from input(s) + withdrawals + refunds
var consumedValue uint64
for _, tmpInput := range tx.Inputs() {
tmpUtxo, err := ls.UtxoById(tmpInput)
Expand All @@ -195,6 +195,12 @@ func UtxoValidateValueNotConservedUtxo(tx common.Transaction, slot uint64, ls co
for _, tmpWithdrawalAmount := range tx.Withdrawals() {
consumedValue += tmpWithdrawalAmount
}
for _, cert := range tx.Certificates() {
switch cert.(type) {
case *common.StakeDeregistrationCertificate:
consumedValue += uint64(tmpPparams.KeyDeposit)
}
}
// Calculate produced value
// produced = value from output(s) + fee + deposits
var producedValue uint64
Expand All @@ -213,13 +219,7 @@ func UtxoValidateValueNotConservedUtxo(tx common.Transaction, slot uint64, ls co
producedValue += uint64(tmpPparams.PoolDeposit)
}
case *common.StakeRegistrationCertificate:
certs, err := ls.StakeRegistration(tmpCert.StakeRegistration.Credential)
if err != nil {
return err
}
if len(certs) == 0 {
producedValue += uint64(tmpPparams.KeyDeposit)
}
producedValue += uint64(tmpPparams.KeyDeposit)
}
}
if consumedValue == producedValue {
Expand Down
29 changes: 8 additions & 21 deletions ledger/babbage/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,6 @@ func TestUtxoValidateValueNotConservedUtxo(t *testing.T) {
var testInputAmount uint64 = 555666777
var testFee uint64 = 123456
var testStakeDeposit uint64 = 2_000_000
var testStakeCred1 = []byte{0x01, 0x23, 0x45}
var testStakeCred2 = []byte{0xab, 0xcd, 0xef}
testOutputExactAmount := testInputAmount - testFee
testOutputUnderAmount := testOutputExactAmount - 999
testOutputOverAmount := testOutputExactAmount + 999
Expand Down Expand Up @@ -559,13 +557,6 @@ func TestUtxoValidateValueNotConservedUtxo(t *testing.T) {
},
},
},
MockStakeRegistration: []common.StakeRegistrationCertificate{
{
StakeRegistration: common.StakeCredential{
Credential: testStakeCred2,
},
},
},
}
testSlot := uint64(0)
testProtocolParams := &babbage.BabbageProtocolParameters{
Expand All @@ -590,18 +581,16 @@ func TestUtxoValidateValueNotConservedUtxo(t *testing.T) {
}
},
)
// First stake registration
// Stake registration
t.Run(
"first stake registration",
"stake registration",
func(t *testing.T) {
testTx.Body.TxOutputs[0].OutputAmount.Amount = testOutputExactAmount - testStakeDeposit
testTx.Body.TxCertificates = []common.CertificateWrapper{
{
Type: common.CertificateTypeStakeRegistration,
Certificate: &common.StakeRegistrationCertificate{
StakeRegistration: common.StakeCredential{
Credential: testStakeCred1,
},
StakeRegistration: common.StakeCredential{},
},
},
}
Expand All @@ -619,18 +608,16 @@ func TestUtxoValidateValueNotConservedUtxo(t *testing.T) {
}
},
)
// Second stake registration
// Stake deregistration
t.Run(
"second stake registration",
"stake deregistration",
func(t *testing.T) {
testTx.Body.TxOutputs[0].OutputAmount.Amount = testOutputExactAmount
testTx.Body.TxOutputs[0].OutputAmount.Amount = testOutputExactAmount + testStakeDeposit
testTx.Body.TxCertificates = []common.CertificateWrapper{
{
Type: common.CertificateTypeStakeRegistration,
Certificate: &common.StakeRegistrationCertificate{
StakeRegistration: common.StakeCredential{
Credential: testStakeCred2,
},
Certificate: &common.StakeDeregistrationCertificate{
StakeDeregistration: common.StakeCredential{},
},
},
}
Expand Down
16 changes: 8 additions & 8 deletions ledger/conway/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func UtxoValidateValueNotConservedUtxo(tx common.Transaction, slot uint64, ls co
return errors.New("pparams are not expected type")
}
// Calculate consumed value
// consumed = value from input(s) + withdrawals + refunds(?)
// consumed = value from input(s) + withdrawals + refunds
var consumedValue uint64
for _, tmpInput := range tx.Inputs() {
tmpUtxo, err := ls.UtxoById(tmpInput)
Expand All @@ -191,6 +191,12 @@ func UtxoValidateValueNotConservedUtxo(tx common.Transaction, slot uint64, ls co
for _, tmpWithdrawalAmount := range tx.Withdrawals() {
consumedValue += tmpWithdrawalAmount
}
for _, cert := range tx.Certificates() {
switch cert.(type) {
case *common.StakeDeregistrationCertificate:
consumedValue += uint64(tmpPparams.KeyDeposit)
}
}
// Calculate produced value
// produced = value from output(s) + fee + deposits
var producedValue uint64
Expand All @@ -209,13 +215,7 @@ func UtxoValidateValueNotConservedUtxo(tx common.Transaction, slot uint64, ls co
producedValue += uint64(tmpPparams.PoolDeposit)
}
case *common.StakeRegistrationCertificate:
certs, err := ls.StakeRegistration(tmpCert.StakeRegistration.Credential)
if err != nil {
return err
}
if len(certs) == 0 {
producedValue += uint64(tmpPparams.KeyDeposit)
}
producedValue += uint64(tmpPparams.KeyDeposit)
}
}
if consumedValue == producedValue {
Expand Down
29 changes: 8 additions & 21 deletions ledger/conway/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,6 @@ func TestUtxoValidateValueNotConservedUtxo(t *testing.T) {
var testInputAmount uint64 = 555666777
var testFee uint64 = 123456
var testStakeDeposit uint64 = 2_000_000
var testStakeCred1 = []byte{0x01, 0x23, 0x45}
var testStakeCred2 = []byte{0xab, 0xcd, 0xef}
testOutputExactAmount := testInputAmount - testFee
testOutputUnderAmount := testOutputExactAmount - 999
testOutputOverAmount := testOutputExactAmount + 999
Expand Down Expand Up @@ -562,13 +560,6 @@ func TestUtxoValidateValueNotConservedUtxo(t *testing.T) {
},
},
},
MockStakeRegistration: []common.StakeRegistrationCertificate{
{
StakeRegistration: common.StakeCredential{
Credential: testStakeCred2,
},
},
},
}
testSlot := uint64(0)
testProtocolParams := &conway.ConwayProtocolParameters{
Expand All @@ -593,18 +584,16 @@ func TestUtxoValidateValueNotConservedUtxo(t *testing.T) {
}
},
)
// First stake registration
// Stake registration
t.Run(
"first stake registration",
"stake registration",
func(t *testing.T) {
testTx.Body.TxOutputs[0].OutputAmount.Amount = testOutputExactAmount - testStakeDeposit
testTx.Body.TxCertificates = []common.CertificateWrapper{
{
Type: common.CertificateTypeStakeRegistration,
Certificate: &common.StakeRegistrationCertificate{
StakeRegistration: common.StakeCredential{
Credential: testStakeCred1,
},
StakeRegistration: common.StakeCredential{},
},
},
}
Expand All @@ -622,18 +611,16 @@ func TestUtxoValidateValueNotConservedUtxo(t *testing.T) {
}
},
)
// Second stake registration
// Stake deregistration
t.Run(
"second stake registration",
"stake deregistration",
func(t *testing.T) {
testTx.Body.TxOutputs[0].OutputAmount.Amount = testOutputExactAmount
testTx.Body.TxOutputs[0].OutputAmount.Amount = testOutputExactAmount + testStakeDeposit
testTx.Body.TxCertificates = []common.CertificateWrapper{
{
Type: common.CertificateTypeStakeRegistration,
Certificate: &common.StakeRegistrationCertificate{
StakeRegistration: common.StakeCredential{
Credential: testStakeCred2,
},
Certificate: &common.StakeDeregistrationCertificate{
StakeDeregistration: common.StakeCredential{},
},
},
}
Expand Down
Loading
Loading