version: 2
models:
  - name: silver__transactions
    recent_date_filter: &recent_date_filter
      config:
        where: _inserted_timestamp >= current_date - 7
    data_tests:
      - dbt_utils.unique_combination_of_columns:
          combination_of_columns:
            - TX_ID
          where: block_timestamp::date > current_date - 30
    columns:
      - name: BLOCK_TIMESTAMP
        description: "{{ doc('block_timestamp') }}"
        data_tests:
          - not_null: *recent_date_filter
      - name: BLOCK_ID
        description: "{{ doc('block_id') }}"
        data_tests:
          - not_null: *recent_date_filter
      - name: RECENT_BLOCK_HASH
        description: Previous block's hash value
        data_tests:
          - not_null: *recent_date_filter
      - name: TX_ID
        description: "{{ doc('tx_id') }}"
        data_tests:
          - not_null: *recent_date_filter
      - name: FEE
        description: Transaction fee (in lamports)
        data_tests: 
          - null_threshold:
              threshold_percent: 0.99 # some older transactions have valid null fees
              where: block_timestamp::date > current_date - 30
      - name: SUCCEEDED
        description: "{{ doc('tx_succeeded') }}"
        data_tests: 
          - not_null: *recent_date_filter
      - name: SIGNERS
        description: List of accounts that signed the transaction
      - name: ACCOUNT_KEYS
        description: List of accounts that are referenced by pre/post sol/token balances objects
        data_tests: 
          - not_null: *recent_date_filter
      - name: PRE_BALANCES
        description: List of pre-transaction balances for different accounts
      - name: POST_BALANCES
        description: List of post-transaction balances for different accounts
      - name: PRE_TOKEN_BALANCES
        description: List of pre-transaction token balances for different token accounts
      - name: POST_TOKEN_BALANCES
        description: List of post-transaction token balances for different token accounts
      - name: INSTRUCTIONS
        description: "{{ doc('instruction') }}"
        data_tests: 
          - not_null: *recent_date_filter
      - name: INNER_INSTRUCTIONS
        description: "{{ doc('inner_instruction') }}"
        data_tests: 
          - not_null:
              where: SUCCEEDED and _inserted_timestamp >= current_date - 7
      - name: LOG_MESSAGES
        description: Array of log messages written by the program for this transaction
      - name: ADDRESS_TABLE_LOOKUPS
        description: Array of lookup keys used associate additional account keys with the transactions.  Valid for version > 0 transactions.
      - name: UNITS_CONSUMED
        description: The number of compute units consumed by the program. 
      - name: UNIT_LIMIT
        description: The max number of compute units that can be consumed by the program. 
      - name: TX_SIZE
        description: The size of the transaction in bytes. 
      - name: VERSION
        description: Transaction version, legacy version is listed as NULL or 'legacy'
      - name: TX_INDEX
        description: "{{ doc('tx_index') }}"
        # TODO: update once we know when the first partition is that has tx_index values
        # data_tests:
        #   - not_null:
        #       config:
        #         where: >
        #           _inserted_timestamp >= current_date - 7
        #           AND _partition_id >= 150300
      - name: _INSERTED_TIMESTAMP
        description: "{{ doc('_inserted_timestamp') }}"
        data_tests: 
          - not_null
