7 "golang.org/x/crypto/sha3"
9 "github.com/bytom/crypto/ed25519"
10 "github.com/bytom/protocol/bc"
11 "github.com/bytom/protocol/bc/types"
12 "github.com/bytom/protocol/vm"
13 "github.com/bytom/protocol/vm/vmutil"
14 "github.com/bytom/testutil"
17 /*func TestBadMaxIssuanceWindow(t *testing.T) {
18 ctx := context.Background()
19 c, b1 := newTestChain(t, time.Now())
20 c.MaxIssuanceWindow = time.Second
22 issueTx, _, _ := issue(t, nil, nil, 1)
24 got, _, err := c.GenerateBlock(ctx, b1, state.Empty(), time.Now(), []*types.Tx{issueTx})
28 if len(got.Transactions) != 0 {
29 t.Error("expected issuance past max issuance window to be rejected")
33 type testDest struct {
34 privKey ed25519.PrivateKey
37 func newDest(t testing.TB) *testDest {
38 _, priv, err := ed25519.GenerateKey(nil)
40 testutil.FatalErr(t, err)
47 func (d *testDest) sign(t testing.TB, tx *types.Tx, index uint32) {
48 txsighash := tx.SigHash(index)
49 prog, _ := vm.Assemble(fmt.Sprintf("0x%x TXSIGHASH EQUAL", txsighash.Bytes()))
50 h := sha3.Sum256(prog)
51 sig := ed25519.Sign(d.privKey, h[:])
52 tx.Inputs[index].SetArguments([][]byte{vm.Int64Bytes(0), sig, prog})
55 func (d testDest) controlProgram() ([]byte, error) {
56 pub := d.privKey.Public().(ed25519.PublicKey)
57 return vmutil.P2SPMultiSigProgram([]ed25519.PublicKey{pub}, 1)
60 type testAsset struct {
65 func newAsset(t testing.TB) *testAsset {
67 cp, _ := dest.controlProgram()
68 assetID := bc.ComputeAssetID(cp, 1, &bc.EmptyStringHash)
76 func issue(t testing.TB, asset *testAsset, dest *testDest, amount uint64) (*types.Tx, *testAsset, *testDest) {
83 assetCP, _ := asset.controlProgram()
84 destCP, _ := dest.controlProgram()
85 tx := types.NewTx(types.TxData{
87 Inputs: []*types.TxInput{
88 types.NewIssuanceInput([]byte{1}, amount, assetCP, nil, nil),
90 Outputs: []*types.TxOutput{
91 types.NewTxOutput(asset.AssetID, amount, destCP),
96 return tx, asset, dest