Skip to content

Commit

Permalink
Merge pull request ethereum#203 from tomochain/revert-153-randomize
Browse files Browse the repository at this point in the history
Revert "Randomization implementation"
  • Loading branch information
ngtuna authored Oct 5, 2018
2 parents 791769c + c0a5890 commit 40d4ba9
Show file tree
Hide file tree
Showing 15,771 changed files with 68 additions and 6,035,910 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "tests"]
path = tests/testdata
url = https://github.com/ethereum/tests
5 changes: 2 additions & 3 deletions cmd/tomo/dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ var daoProForkGenesis = `{
}
}`

var daoGenesisHash = common.HexToHash("f2ea0466bf5a07cb7407474d9fbaae6e275127f038ca57a673b833234204f4fd")
var daoGenesisHash = common.HexToHash("5e1fc79cb4ffa4739177b5408045cd5d51c6cf766133f23f7cd72ee1f8d790e0")
var daoGenesisForkBlock = big.NewInt(314)

// TestDAOForkBlockNewChain tests that the DAO hard-fork number and the nodes support/opposition is correctly
Expand Down Expand Up @@ -127,11 +127,10 @@ func testDAOForkBlockNewChain(t *testing.T, test int, genesis string, expectBloc
}
defer db.Close()

genesisHash := common.HexToHash("2efa267fef46877ac2659209e2299f97b0afc2a797ee8672db21920a5151e0aa")
genesisHash := common.HexToHash("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3")
if genesis != "" {
genesisHash = daoGenesisHash
}
t.Log("genesisHash", genesisHash.String())
config, err := core.GetChainConfig(db, genesisHash)
if err != nil {
t.Errorf("test %d: failed to retrieve chain config: %v", test, err)
Expand Down
14 changes: 0 additions & 14 deletions common/constants.go

This file was deleted.

4 changes: 2 additions & 2 deletions contracts/randomize/contract/randomize.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

87 changes: 6 additions & 81 deletions contracts/randomize/randomize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,19 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/contracts"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
)

var (
epocNumber = int64(12)
key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
addr = crypto.PubkeyToAddress(key.PublicKey)
byte0 = make([][32]byte, epocNumber)
acc1Key, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a")
acc1Addr = crypto.PubkeyToAddress(acc1Key.PublicKey)
key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
addr = crypto.PubkeyToAddress(key.PublicKey)
byte0 = make([][32]byte, 2)
)

func TestRandomize(t *testing.T) {
contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(100000000000000)}})
contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}})
transactOpts := bind.NewKeyedTransactor(key)
transactOpts.GasLimit = 1000000

randomizeAddress, randomize, err := DeployRandomize(transactOpts, contractBackend, big.NewInt(2))
t.Log("contract address", randomizeAddress.String())
Expand All @@ -61,80 +55,11 @@ func TestRandomize(t *testing.T) {
return true
}
contractBackend.ForEachStorageAt(ctx, randomizeAddress, nil, f)

s, err := randomize.SetSecret(byte0)
if err != nil {
t.Fatalf("can't set secret: %v", err)
t.Fatalf("can't get secret: %v", err)
}
t.Log("tx data", s)
contractBackend.Commit()
}

func TestSendTxRandomizeSecretAndOpening(t *testing.T) {
genesis := core.GenesisAlloc{acc1Addr: {Balance: big.NewInt(1000000000000)}}
backend := backends.NewSimulatedBackend(genesis)
backend.Commit()
signer := types.HomesteadSigner{}
ctx := context.Background()

transactOpts := bind.NewKeyedTransactor(acc1Key)
transactOpts.GasLimit = 4200000
epocNumber := uint64(900)
randomizeAddr, randomizeContract, err := DeployRandomize(transactOpts, backend, new(big.Int).SetInt64(0))
if err != nil {
t.Fatalf("Can't deploy randomize SC: %v", err)
}
backend.Commit()

nonce := uint64(1)
randomizeKeyValue := contracts.RandStringByte(32)
tx, err := contracts.BuildTxSecretRandomize(nonce, randomizeAddr, epocNumber, randomizeKeyValue)
if err != nil {
t.Fatalf("Can't create tx randomize secret: %v", err)
}
tx, err = types.SignTx(tx, signer, acc1Key)
if err != nil {
t.Fatalf("Can't sign tx randomize secret: %v", err)
}

err = backend.SendTransaction(ctx, tx)
if err != nil {
t.Fatalf("Can't send tx for create randomize secret: %v", err)
}
backend.Commit()
// Increment nonce.
nonce++
// Set opening.
tx, err = contracts.BuildTxOpeningRandomize(nonce, randomizeAddr, randomizeKeyValue)
if err != nil {
t.Fatalf("Can't create tx randomize opening: %v", err)
}
tx, err = types.SignTx(tx, signer, acc1Key)
if err != nil {
t.Fatalf("Can't sign tx randomize opening: %v", err)
}

err = backend.SendTransaction(ctx, tx)
if err != nil {
t.Fatalf("Can't send tx for create randomize opening: %v", err)
}
backend.Commit()

// Get randomize secret from SC.
secrets, err := randomizeContract.GetSecret(acc1Addr)
if err != nil {
t.Error("Fail get secrets from randomize", err)
}
if len(secrets) <= 0 {
t.Error("Empty get secrets from SC", err)
}
// Decrypt randomize from SC.
opening, err := randomizeContract.GetOpening(acc1Addr)
if err != nil {
t.Fatalf("Can't get secret from SC: %v", err)
}
randomize, err := contracts.DecryptRandomizeFromSecretsAndOpening(secrets, opening)
t.Log("randomize", randomize)
if err != nil {
t.Error("Can't decrypt secret and opening", err)
}
}
Loading

0 comments on commit 40d4ba9

Please sign in to comment.