Exemple #1
0
func TestIngest(t *testing.T) {
	tt := test.Start(t).ScenarioWithoutHorizon("kahuna")
	defer tt.Finish()

	s := ingest(tt)
	tt.Require.NoError(s.Err)
	tt.Assert.Equal(59, s.Ingested)

	hq := &history.Q{Repo: tt.HorizonRepo()}

	// Ensure the root account was created
	var root history.Account
	err := hq.AccountByID(&root, 1)

	tt.Assert.NoError(err)
	tt.Assert.Equal(int64(1), root.ID)
	tt.Assert.Equal(keypair.Master(network.TestNetworkPassphrase).Address(), root.Address)

	// Test that re-importing fails
	s.Err = nil
	s.Run()
	tt.Require.Error(s.Err, "Reimport didn't fail as expected")

	// Test that re-importing fails with allowing clear succeeds
	s.Err = nil
	s.ClearExisting = true
	s.Run()
	tt.Require.NoError(s.Err, "Couldn't re-import, even with clear allowed")
}
Exemple #2
0
// ingestLedger ingests the current ledger
func (is *Session) ingestLedger() {
	if is.Err != nil {
		return
	}

	start := time.Now()
	is.Ingestion.Ledger(
		is.Cursor.LedgerID(),
		is.Cursor.Ledger(),
		is.Cursor.SuccessfulTransactionCount(),
		is.Cursor.SuccessfulLedgerOperationCount(),
	)

	// If this is ledger 1, create the root account
	if is.Cursor.LedgerSequence() == 1 {
		is.Ingestion.Account(1, keypair.Master(is.Network).Address())
	}

	for is.Cursor.NextTx() {
		is.ingestTransaction()
	}

	is.Ingested++
	if is.Metrics != nil {
		is.Metrics.IngestLedgerTimer.Update(time.Since(start))
	}

	return
}