# frozen_string_literal: true

require 'spec_helper'

describe Lightning::Wire::LightningMessages::UpdateAddHtlc do
  let(:channel_id) { '775762ca0b9abd68b732548ad406112dc8aab4069a3aa501b9fad4df93d215af' }
  let(:id) { 2 }
  let(:amount_msat) { 3 }
  let(:payment_hash) { '0000000000000000000000000000000000000000000000000000000000000000' }
  let(:cltv_expiry) { 4 }
  let(:onion_routing_packet) { "00" * 1366 }
  let(:payload) do
    '0080775762ca0b9abd68b732548ad406112dc8aab4069a3aa501b9fad4df93d2' \
    '15af000000000000000200000000000000030000000000000000000000000000' \
    '0000000000000000000000000000000000000000000400000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '0000000000000000000000000000000000000000000000000000000000000000' \
    '000000000000000000000000'
  end

  describe '#load' do
    subject { described_class.load(payload.htb) }

    it { expect(subject.channel_id).to eq channel_id }
    it { expect(subject.id).to eq id }
    it { expect(subject.amount_msat).to eq amount_msat }
    it { expect(subject.payment_hash).to eq payment_hash }
    it { expect(subject.cltv_expiry).to eq cltv_expiry }
    it { expect(subject.onion_routing_packet).to eq onion_routing_packet }
  end

  describe '#to_payload' do
    subject do
      described_class.new(
        channel_id: channel_id,
        id: id,
        amount_msat: amount_msat,
        payment_hash: payment_hash,
        cltv_expiry: cltv_expiry,
        onion_routing_packet: onion_routing_packet
      ).to_payload.bth
    end

    it { is_expected.to eq payload }
  end
end
