Exemple #1
0
func TestHandleDirectoryBlockHead(t *testing.T) {
	context := testHelper.CreateWebContext()

	HandleDirectoryBlockHead(context)
	expectedHead := "508e19f65a7fc7e9cfa5a73281b5e08115ed25a1af5723350e5c21fc92c39b40"

	if strings.Contains(testHelper.GetBody(context), expectedHead) == false {
		t.Errorf("Context does not contain proper DBlock Head - %v vs %v", testHelper.GetBody(context), expectedHead)
	}

	/*
		j := testHelper.GetRespText(context)
		head := new(DirectoryBlockHeadResponse)
		err := primitives.DecodeJSONString(j, head)
		if err != nil {
			panic(err)
		}

		hash := head.KeyMR

		testHelper.ClearContextResponseWriter(context)
		HandleDirectoryBlock(context, hash)

		j = testHelper.GetRespText(context)
		block := new(DBlock)
		err = primitives.DecodeJSONString(j, block)
		if err != nil {
			panic(err)
		}

		t.Errorf("%v", j)
	*/
}
Exemple #2
0
func TestHandleEntryBlock(t *testing.T) {
	context := testHelper.CreateWebContext()
	chain, err := primitives.HexToHash("df3ade9eec4b08d5379cc64270c30ea7315d8a8a1a69efe2b98a60ecdd69e604")
	if err != nil {
		t.Error(err)
	}

	dbo := context.Server.Env["state"].(interfaces.IState).GetAndLockDB()
	defer context.Server.Env["state"].(interfaces.IState).UnlockDB()

	blocks, err := dbo.FetchAllEBlocksByChain(chain)
	if err != nil {
		t.Error(err)
	}
	fetched := 0
	for _, b := range blocks {
		hash := b.(*entryBlock.EBlock).DatabasePrimaryIndex().String()
		hash2 := b.(*entryBlock.EBlock).DatabaseSecondaryIndex().String()

		testHelper.ClearContextResponseWriter(context)
		HandleEntryBlock(context, hash)

		eBlock := new(EBlock)

		testHelper.UnmarshalRespDirectly(context, eBlock)

		if eBlock.Header.ChainID != "df3ade9eec4b08d5379cc64270c30ea7315d8a8a1a69efe2b98a60ecdd69e604" {
			t.Errorf("Wrong ChainID - %v", eBlock.Header.ChainID)
			t.Errorf("eBlock - %v", eBlock)
			t.Errorf("%v", testHelper.GetBody(context))
		}

		if eBlock.Header.DBHeight != int64(b.(*entryBlock.EBlock).GetHeader().GetDBHeight()) {
			t.Errorf("DBHeight is wrong - %v vs %v", eBlock.Header.DBHeight, b.(*entryBlock.EBlock).GetHeader().GetDBHeight())
		}

		testHelper.ClearContextResponseWriter(context)
		HandleEntryBlock(context, hash2)

		eBlock = new(EBlock)

		testHelper.UnmarshalRespDirectly(context, eBlock)

		if eBlock.Header.ChainID != "df3ade9eec4b08d5379cc64270c30ea7315d8a8a1a69efe2b98a60ecdd69e604" {
			t.Errorf("Wrong ChainID - %v", eBlock.Header.ChainID)
			t.Errorf("%v", testHelper.GetBody(context))
		}

		if eBlock.Header.DBHeight != int64(b.(*entryBlock.EBlock).GetHeader().GetDBHeight()) {
			t.Errorf("DBHeight is wrong - %v vs %v", eBlock.Header.DBHeight, b.(*entryBlock.EBlock).GetHeader().GetDBHeight())
		}

		fetched++
	}
	if fetched != testHelper.BlockCount {
		t.Errorf("Fetched %v blocks, expected %v", fetched, testHelper.BlockCount)
	}
}
Exemple #3
0
func TestHandleGetFee(t *testing.T) {
	context := testHelper.CreateWebContext()

	HandleGetFee(context)

	if strings.Contains(testHelper.GetBody(context), "") == false {
		t.Errorf("%v", testHelper.GetBody(context))
	}
}
Exemple #4
0
func TestHandleFactoidBalance(t *testing.T) {
	context := testHelper.CreateWebContext()
	eckey := testHelper.NewFactoidRCDAddressString(0)

	//t.Logf("%v\n", eckey)

	HandleFactoidBalance(context, eckey)

	//expectedAmount := fmt.Sprintf("%v", uint64(testHelper.BlockCount)*testHelper.DefaultCoinbaseAmount)
	expectedAmount := "999889000"
	if strings.Contains(testHelper.GetBody(context), expectedAmount) == false {
		t.Errorf("%v", testHelper.GetBody(context))
	}
}
Exemple #5
0
func TestHandleEntryCreditBalance(t *testing.T) {
	context := testHelper.CreateWebContext()
	eckey := testHelper.NewECAddressPublicKeyString(0)

	HandleEntryCreditBalance(context, eckey)

	expectedAmount := "2000"
	if strings.Contains(testHelper.GetBody(context), expectedAmount) == false {
		t.Errorf("%v", testHelper.GetBody(context))
	}
	testHelper.ClearContextResponseWriter(context)

	eckey = testHelper.NewECAddressString(0)

	HandleEntryCreditBalance(context, eckey)

	if strings.Contains(testHelper.GetBody(context), expectedAmount) == false {
		t.Errorf("%v", testHelper.GetBody(context))
	}
}
Exemple #6
0
/*
func TestHandleEntry(t *testing.T) {
	context := testHelper.CreateWebContext()
	hash := ""

	HandleEntry(context, hash)

	if strings.Contains(testHelper.GetBody(context), "") == false {
		t.Errorf("%v", testHelper.GetBody(context))
	}
}
*/
func TestHandleChainHead(t *testing.T) {
	context := testHelper.CreateWebContext()
	hash := "000000000000000000000000000000000000000000000000000000000000000d"

	HandleChainHead(context, hash)

	if strings.Contains(testHelper.GetBody(context), "508e19f65a7fc7e9cfa5a73281b5e08115ed25a1af5723350e5c21fc92c39b40") == false {
		t.Errorf("Invalid directory block head: %v", testHelper.GetBody(context))
	}

	hash = "000000000000000000000000000000000000000000000000000000000000000a"

	testHelper.ClearContextResponseWriter(context)
	HandleChainHead(context, hash)

	if strings.Contains(testHelper.GetBody(context), "956c41312070f58c628ca8027297e0af0aaaa7b8af7f84283fc5ad21a49cc00a") == false {
		t.Errorf("Invalid admin block head: %v", testHelper.GetBody(context))
	}

	hash = "000000000000000000000000000000000000000000000000000000000000000c"

	testHelper.ClearContextResponseWriter(context)
	HandleChainHead(context, hash)

	if strings.Contains(testHelper.GetBody(context), "6179a316ad0d1eeda5298f475c078f69b75085d88ff65a206e5bca1bf2cb081d") == false {
		t.Errorf("Invalid entry credit block head: %v", testHelper.GetBody(context))
	}

	hash = "000000000000000000000000000000000000000000000000000000000000000f"

	testHelper.ClearContextResponseWriter(context)
	HandleChainHead(context, hash)

	if strings.Contains(testHelper.GetBody(context), "c6cd2ab21d75af1e8589e1eb441411838a508d0674eb294bac4efdc591c3fef4") == false {
		t.Errorf("Invalid factoid block head: %v", testHelper.GetBody(context))
	}

	hash = "6e7e64ac45ff57edbf8537a0c99fba2e9ee351ef3d3f4abd93af9f01107e592c"

	testHelper.ClearContextResponseWriter(context)
	HandleChainHead(context, hash)

	if strings.Contains(testHelper.GetBody(context), "1127ed78303976572f25dfba2a058e475234c079ea0d0f645280d03caff08347") == false {
		t.Errorf("Invalid entry block head: %v", testHelper.GetBody(context))
	}

	hash = "df3ade9eec4b08d5379cc64270c30ea7315d8a8a1a69efe2b98a60ecdd69e604"

	testHelper.ClearContextResponseWriter(context)
	HandleChainHead(context, hash)

	if strings.Contains(testHelper.GetBody(context), "8d70d04d3189b31bc7a1d12564731ec24775b0a082f23505bba380810c516ca4") == false {
		t.Errorf("Invalid anchor entry block head: %v", testHelper.GetBody(context))
	}
}
Exemple #7
0
func TestHandleDirectoryBlock(t *testing.T) {
	context := testHelper.CreateWebContext()
	hash := "508e19f65a7fc7e9cfa5a73281b5e08115ed25a1af5723350e5c21fc92c39b40"

	HandleDirectoryBlock(context, hash)

	if testHelper.GetBody(context) == "" {
		t.Errorf("HandleDirectoryBlock returned empty block")
		t.FailNow()
	}

	if strings.Contains(testHelper.GetBody(context), "000000000000000000000000000000000000000000000000000000000000000a") == false {
		t.Errorf("%v", testHelper.GetBody(context))
	}

	if strings.Contains(testHelper.GetBody(context), "956c41312070f58c628ca8027297e0af0aaaa7b8af7f84283fc5ad21a49cc00a") == false {
		t.Errorf("%v", testHelper.GetBody(context))
	}

	if strings.Contains(testHelper.GetBody(context), "000000000000000000000000000000000000000000000000000000000000000c") == false {
		t.Errorf("%v", testHelper.GetBody(context))
	}

	if strings.Contains(testHelper.GetBody(context), "6179a316ad0d1eeda5298f475c078f69b75085d88ff65a206e5bca1bf2cb081d") == false {
		t.Errorf("%v", testHelper.GetBody(context))
	}

	if strings.Contains(testHelper.GetBody(context), "000000000000000000000000000000000000000000000000000000000000000f") == false {
		t.Errorf("%v", testHelper.GetBody(context))
	}

	if strings.Contains(testHelper.GetBody(context), "c6cd2ab21d75af1e8589e1eb441411838a508d0674eb294bac4efdc591c3fef4") == false {
		t.Errorf("%v", testHelper.GetBody(context))
	}

	if strings.Contains(testHelper.GetBody(context), "6e7e64ac45ff57edbf8537a0c99fba2e9ee351ef3d3f4abd93af9f01107e592c") == false {
		t.Errorf("%v", testHelper.GetBody(context))
	}

	if strings.Contains(testHelper.GetBody(context), "1127ed78303976572f25dfba2a058e475234c079ea0d0f645280d03caff08347") == false {
		t.Errorf("%v", testHelper.GetBody(context))
	}

	if strings.Contains(testHelper.GetBody(context), "df3ade9eec4b08d5379cc64270c30ea7315d8a8a1a69efe2b98a60ecdd69e604") == false {
		t.Errorf("%v", testHelper.GetBody(context))
	}

	if strings.Contains(testHelper.GetBody(context), "8d70d04d3189b31bc7a1d12564731ec24775b0a082f23505bba380810c516ca4") == false {
		t.Errorf("%v", testHelper.GetBody(context))
	}

	if strings.Contains(testHelper.GetBody(context), "\"Timestamp\":74580") == false {
		t.Errorf("%v", testHelper.GetBody(context))
	}

}
Exemple #8
0
func TestHandleGetRaw(t *testing.T) {
	type RawData struct {
		Hash1 string
		Hash2 string
		Raw   string
	}

	toTest := []RawData{}
	var err error

	blockSet := testHelper.CreateTestBlockSet(nil)

	aBlock := blockSet.ABlock
	raw := RawData{}
	raw.Hash1 = aBlock.DatabasePrimaryIndex().String()
	raw.Hash2 = aBlock.DatabaseSecondaryIndex().String()
	hex, err := aBlock.MarshalBinary()
	if err != nil {
		panic(err)
	}
	raw.Raw = primitives.EncodeBinary(hex)
	toTest = append(toTest, raw) //1

	eBlock := blockSet.EBlock
	raw = RawData{}
	raw.Hash1 = eBlock.DatabasePrimaryIndex().String()
	raw.Hash2 = eBlock.DatabaseSecondaryIndex().String()
	hex, err = eBlock.MarshalBinary()
	if err != nil {
		panic(err)
	}
	raw.Raw = primitives.EncodeBinary(hex)
	toTest = append(toTest, raw) //2

	ecBlock := blockSet.ECBlock
	raw = RawData{}
	raw.Hash1 = ecBlock.(interfaces.DatabaseBatchable).DatabasePrimaryIndex().String()
	raw.Hash2 = ecBlock.(interfaces.DatabaseBatchable).DatabaseSecondaryIndex().String()
	hex, err = ecBlock.MarshalBinary()
	if err != nil {
		panic(err)
	}
	raw.Raw = primitives.EncodeBinary(hex)
	toTest = append(toTest, raw) //3

	fBlock := blockSet.FBlock
	raw = RawData{}
	raw.Hash1 = fBlock.(interfaces.DatabaseBatchable).DatabasePrimaryIndex().String()
	raw.Hash2 = fBlock.(interfaces.DatabaseBatchable).DatabaseSecondaryIndex().String()
	hex, err = fBlock.MarshalBinary()
	if err != nil {
		panic(err)
	}
	raw.Raw = primitives.EncodeBinary(hex)
	toTest = append(toTest, raw) //4

	dBlock := blockSet.DBlock
	raw = RawData{}
	raw.Hash1 = dBlock.DatabasePrimaryIndex().String()
	raw.Hash2 = dBlock.DatabaseSecondaryIndex().String()
	hex, err = dBlock.MarshalBinary()
	if err != nil {
		panic(err)
	}
	raw.Raw = primitives.EncodeBinary(hex)
	toTest = append(toTest, raw) //5

	context := testHelper.CreateWebContext()
	for i, v := range toTest {
		testHelper.ClearContextResponseWriter(context)
		HandleGetRaw(context, v.Hash1)

		if strings.Contains(testHelper.GetBody(context), v.Raw) == false {
			t.Errorf("Looking for %v", v.Hash1)
			t.Errorf("GetRaw %v/%v from Hash1 failed - %v", i, len(toTest), testHelper.GetBody(context))
		}

		testHelper.ClearContextResponseWriter(context)
		HandleGetRaw(context, v.Hash2)

		if strings.Contains(testHelper.GetBody(context), v.Raw) == false {
			t.Errorf("Looking for %v", v.Hash2)
			t.Errorf("GetRaw %v/%v from Hash2 failed - %v", i, len(toTest), testHelper.GetBody(context))
		}
	}
}