@@ -5,6 +5,7 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactionsTest do
55 alias Ecto.Multi
66 alias Explorer.Chain . { Block , Data , Wei , PendingBlockOperation , Transaction , InternalTransaction }
77 alias Explorer.Chain.Import.Runner.InternalTransactions
8+ alias Explorer.Migrator.DeleteZeroValueInternalTransactions
89
910 setup do
1011 config = Application . get_env ( :ethereum_jsonrpc , EthereumJSONRPC.Geth )
@@ -595,6 +596,126 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactionsTest do
595596 end
596597 end
597598
599+ describe "prepare_data/1 zero value filtering" do
600+ setup do
601+ original_config = Application . get_env ( :explorer , DeleteZeroValueInternalTransactions )
602+
603+ on_exit ( fn ->
604+ Application . put_env ( :explorer , DeleteZeroValueInternalTransactions , original_config )
605+ end )
606+
607+ :ok
608+ end
609+
610+ test "removes zero-value call internal transactions before border block" do
611+ Application . put_env ( :explorer , DeleteZeroValueInternalTransactions , enabled: true , storage_period: 0 )
612+ block = insert ( :block )
613+
614+ params = [
615+ % {
616+ type: :call ,
617+ block_number: block . number - 1 ,
618+ value: Wei . from ( Decimal . new ( 0 ) , :wei )
619+ } ,
620+ % {
621+ type: :call ,
622+ block_number: block . number - 1 ,
623+ value: Wei . from ( Decimal . new ( 1 ) , :wei )
624+ } ,
625+ % {
626+ type: "call" ,
627+ block_number: block . number - 1 ,
628+ value: 0
629+ }
630+ ]
631+
632+ result = InternalTransactions . prepare_data ( params )
633+
634+ assert length ( result ) == 1
635+ assert hd ( result ) . value . value == Decimal . new ( 1 )
636+ end
637+
638+ test "does not remove zero-value calls after border block" do
639+ Application . put_env ( :explorer , DeleteZeroValueInternalTransactions , enabled: true , storage_period: 0 )
640+ block = insert ( :block )
641+
642+ params = [
643+ % {
644+ type: :call ,
645+ block_number: block . number + 1 ,
646+ value: Wei . from ( Decimal . new ( 0 ) , :wei )
647+ } ,
648+ % {
649+ type: "call" ,
650+ block_number: block . number + 1 ,
651+ value: 0
652+ }
653+ ]
654+
655+ assert [ _ , _ ] = InternalTransactions . prepare_data ( params )
656+ end
657+
658+ test "does not remove non-call internal transactions" do
659+ Application . put_env ( :explorer , DeleteZeroValueInternalTransactions , enabled: true , storage_period: 0 )
660+ block = insert ( :block )
661+
662+ params = [
663+ % {
664+ type: :create ,
665+ block_number: block . number - 1 ,
666+ value: Wei . from ( Decimal . new ( 0 ) , :wei )
667+ } ,
668+ % {
669+ type: "create" ,
670+ block_number: block . number - 1 ,
671+ value: 0
672+ }
673+ ]
674+
675+ assert [ _ , _ ] = InternalTransactions . prepare_data ( params )
676+ end
677+
678+ test "treats nil value as zero" do
679+ Application . put_env ( :explorer , DeleteZeroValueInternalTransactions , enabled: true , storage_period: 0 )
680+ block = insert ( :block )
681+
682+ params = [
683+ % {
684+ type: :call ,
685+ block_number: block . number - 1 ,
686+ value: nil
687+ } ,
688+ % {
689+ type: "call" ,
690+ block_number: block . number - 1 ,
691+ value: nil
692+ }
693+ ]
694+
695+ assert [ ] == InternalTransactions . prepare_data ( params )
696+ end
697+
698+ test "does not filter anything when feature is disabled" do
699+ Application . put_env ( :explorer , DeleteZeroValueInternalTransactions , enabled: false , storage_period: 0 )
700+ block = insert ( :block )
701+
702+ params = [
703+ % {
704+ type: :call ,
705+ block_number: block . number - 1 ,
706+ value: Wei . from ( Decimal . new ( 0 ) , :wei )
707+ } ,
708+ % {
709+ type: "call" ,
710+ block_number: block . number - 1 ,
711+ value: 0
712+ }
713+ ]
714+
715+ assert [ _ , _ ] = InternalTransactions . prepare_data ( params )
716+ end
717+ end
718+
598719 defp run_internal_transactions ( changes_list , multi \\ Multi . new ( ) ) when is_list ( changes_list ) do
599720 multi
600721 |> InternalTransactions . run ( InternalTransactions . prepare_data ( changes_list ) , % {
0 commit comments