forked from DNAProject/DNA
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix bug: find method ignore current db cache data (DNAProject#20)
* fix bug: find method ignore current db cache data * set amount is nil default value * Add test case
- Loading branch information
Showing
8 changed files
with
177 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package states | ||
|
||
import ( | ||
"testing" | ||
"github.com/ontio/ontology/common" | ||
"bytes" | ||
"math/big" | ||
) | ||
|
||
func TestTransferFrom_Serialize_Deserialize(t *testing.T) { | ||
se := "011aac8bb717039d78e9840de35e82ba62723594" | ||
fr := "011aac8bb717039d78e9840de35e82ba62723594" | ||
to := "011aac8bb717039d78e9840de35e82ba62723594" | ||
|
||
sb, _ := common.HexToBytes(se) | ||
fb, _ := common.HexToBytes(fr) | ||
tb, _ := common.HexToBytes(to) | ||
|
||
sa, _ := common.AddressParseFromBytes(sb) | ||
fa, _ := common.AddressParseFromBytes(fb) | ||
ta, _ := common.AddressParseFromBytes(tb) | ||
|
||
tf := &TransferFrom{ | ||
Version: 0, | ||
Sender: sa, | ||
From: fa, | ||
To: ta, | ||
Value: big.NewInt(1), | ||
} | ||
|
||
bf := new(bytes.Buffer) | ||
if err := tf.Serialize(bf); err != nil { | ||
t.Fatalf("TransferFrom serialize error: %v", err) | ||
} | ||
|
||
trf := new(TransferFrom) | ||
if err := trf.Deserialize(bf); err != nil { | ||
t.Fatalf("TransferFrom deserialize error: %v", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package states | ||
|
||
import ( | ||
"testing" | ||
"github.com/ontio/ontology/common" | ||
"math/big" | ||
"bytes" | ||
) | ||
|
||
func TestState_Serialize_Deserialize(t *testing.T) { | ||
fr := "011aac8bb717039d78e9840de35e82ba62723594" | ||
to := "011aac8bb717039d78e9840de35e82ba62723595" | ||
|
||
fb, _ := common.HexToBytes(fr) | ||
tb, _ := common.HexToBytes(to) | ||
|
||
fa, _ := common.AddressParseFromBytes(fb) | ||
ta, _ := common.AddressParseFromBytes(tb) | ||
|
||
s := &State{ | ||
Version: 0, | ||
From: fa, | ||
To: ta, | ||
Value: big.NewInt(1), | ||
} | ||
|
||
bf := new(bytes.Buffer) | ||
if err := s.Serialize(bf); err != nil { | ||
t.Fatalf("State serialize error: %v", err) | ||
} | ||
|
||
st := new(State) | ||
if err := st.Deserialize(bf); err != nil { | ||
t.Fatalf("State deserialize error: %v", err) | ||
} | ||
} | ||
|
||
func TestTransfers_Serialize_Deserialize(t *testing.T) { | ||
fr := "011aac8bb717039d78e9840de35e82ba62723594" | ||
to := "011aac8bb717039d78e9840de35e82ba62723595" | ||
|
||
fb, _ := common.HexToBytes(fr) | ||
tb, _ := common.HexToBytes(to) | ||
|
||
fa, _ := common.AddressParseFromBytes(fb) | ||
ta, _ := common.AddressParseFromBytes(tb) | ||
|
||
s := &State{ | ||
Version: 0, | ||
From: fa, | ||
To: ta, | ||
Value: big.NewInt(1), | ||
} | ||
|
||
ts := &Transfers{ | ||
Version: 0, | ||
States: []*State{s}, | ||
} | ||
|
||
bf := new(bytes.Buffer) | ||
if err := ts.Serialize(bf); err != nil { | ||
t.Fatalf("Transfers serialize error: %v", err) | ||
} | ||
|
||
trs := new(Transfers) | ||
if err := trs.Deserialize(bf); err != nil { | ||
t.Fatalf("Transfers deserialize error: %v", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package states | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/ontio/ontology/smartcontract/types" | ||
) | ||
|
||
func TestContract_Serialize_Deserialize(t *testing.T) { | ||
vmcode := types.VmCode{ | ||
VmType: types.Native, | ||
Code: []byte{1}, | ||
} | ||
|
||
addr := vmcode.AddressFromVmCode() | ||
|
||
c := &Contract{ | ||
Version: 0, | ||
Code: []byte{1}, | ||
Address: addr, | ||
Method: "init", | ||
Args: []byte{2}, | ||
} | ||
bf := new(bytes.Buffer) | ||
if err := c.Serialize(bf); err != nil { | ||
t.Fatalf("Contract serialize error: %v", err) | ||
} | ||
|
||
v := new(Contract) | ||
if err := v.Deserialize(bf); err != nil { | ||
t.Fatalf("Contract deserialize error: %v", err) | ||
} | ||
} |